Computation of the mean of a random variable to estimate algorithm complexity
I made an incremental algorithm which I would like to evaluate the
complexity. The algorithm works with a sliding window of size n.
To study the complexity, the window is considered full and the data
present are ${x_{1},...,x_{n}}$ . They are assumed to be random, i.i.d,
but with no assumption regarding their distribution. In particular, they
are not necessarily bounded. Finally, the most recent data is $x_{n+1}$.
The complexity of the algorithm depends on the distance from $x_{n+1}$ to
its "nearest lower value" $x_{l}$ whose index is $l=\max\left\{
k\in\{1...n\}\;st\;x_{k}<x_{n+1}\right\}$. The distance $d$ is then
$d=n+1-l$.
$d$ is obviously a random variable, and I would like to determine its
mean, which would give the algorithm complexity.
I first thought $d$ was a geometric variable with argument 1/2 since
$P\left(x_{n+1}\geq x_{n}\right)=1/2$ (which I cannot prove either), so
$E\left[d\right]=2$ but it is not the case. Indeed, $x_{n+1}$ and $x_{n}$
are not independent so $d$ does not follow a geometric law. Moreover, I
did some experiments on Excel to compute $E\left[d\right]$ using different
distributions and it seems it does not depend on the distribution of the
$x_{i}$ but on $n$ (I can not post the image, it confirms this result).
Below is a track I have tried to follow to determine $E\left[d\right]$
which proved unsuccessful:
$E\left[d\right]=\sum_{k=1...n}kP\left(d=k\right)$
and
$\begin{eqnarray*} P\left(d=k\right) & = & P\left(x_{n-k}<x_{n+1}\cap
x_{n-k+1}\geq x_{n+1}\cap...\cap x_{n}\geq x_{n+1}\right)\\ & = &
\forall\lambda_{1},\lambda_{2}\in\mathbb{R}\int_{\lambda_{1}<\lambda_{2}}P\left(x_{n-k}<\lambda_{1}\cap
x_{n+1}\in\left[\lambda_{1};\lambda_{2}\right]\cap\bigcup_{j=n-k+1...n}x_{j}\geq\lambda_{2}\right)d\lambda_{2}d\lambda_{2}\\
& = &
\int_{\lambda_{1}<\lambda_{2}}P\left(x_{n-k}<\lambda_{1}\right)P\left(x_{n+1}\in\left[\lambda_{1};\lambda_{2}\right]\right)\sum_{j=n-k+1...n}P\left(x_{j}\geq\lambda_{2}\right)d\lambda_{2}d\lambda_{2}\\
& = &
\int_{\lambda_{1}<\lambda_{2}}F_{X}\left(\lambda_{1}\right)\left(F_{X}\left(\lambda_{2}\right)-F_{X}\left(\lambda_{1}\right)\right)\sum_{j=n-k+1...n}\left(1-F_{X}\left(\lambda_{2}\right)\right)d\lambda_{2}d\lambda_{2}
\end{eqnarray*}$
But I can not go any further ? Do you have any idea ? Thanks in advance !
Sunday, 18 August 2013
Saturday, 17 August 2013
Fibonacci sequence in Java using for statements
Fibonacci sequence in Java using for statements
I tried making a Java program executing the Fibonacci sequence.
Here's my code:
import java.io.*;
public class Fibonacci{
public static void main(String[]args){
BufferedReader Data=new BufferedReader (new
InputStreamReader(System.in));
int ctr1=0;
int ctr2=0;
int num1=0;
int num2=0;
int num3=0;
try{
System.out.println("How many numbers would you want to see?");
ctr2=Integer.parseInt(Data.readLine());
for(int ans=0; ctr1==ctr2; ctr1++){
num1++;
System.out.println(num2 + "\n" + num1);
ans=num1+num2;
System.out.println(ans);
ans=num3;
}
}catch(IOException err){
System.out.println("Error!" + err);
}catch(NumberFormatException err){
System.out.println("Invald Input!");
}
}
}
Obviously, I'm a beginner in Java and I don't know how to properly use the
for statement. Would somebody be kind enough to make my code work? Or
maybe make a way shorter code that works. I'm a beginner so be cool.
Thanks :)
I tried making a Java program executing the Fibonacci sequence.
Here's my code:
import java.io.*;
public class Fibonacci{
public static void main(String[]args){
BufferedReader Data=new BufferedReader (new
InputStreamReader(System.in));
int ctr1=0;
int ctr2=0;
int num1=0;
int num2=0;
int num3=0;
try{
System.out.println("How many numbers would you want to see?");
ctr2=Integer.parseInt(Data.readLine());
for(int ans=0; ctr1==ctr2; ctr1++){
num1++;
System.out.println(num2 + "\n" + num1);
ans=num1+num2;
System.out.println(ans);
ans=num3;
}
}catch(IOException err){
System.out.println("Error!" + err);
}catch(NumberFormatException err){
System.out.println("Invald Input!");
}
}
}
Obviously, I'm a beginner in Java and I don't know how to properly use the
for statement. Would somebody be kind enough to make my code work? Or
maybe make a way shorter code that works. I'm a beginner so be cool.
Thanks :)
Run Applescript with Growl 2.1 Rules
Run Applescript with Growl 2.1 Rules
Currently, I have a flow set up that results in a file -- 'cb.txt' --
being added to my Dropbox. I get a Growl notification with the Application
Name 'Dropbox' and the Note Title 'cb.txt added'. I want the 'cb.txt
added' notification to run an applescript that will copy the text from
cb.txt to my clipboard. The rules for Growl's notification can be found
here.
Here is the applescript I want to run (when I run it by itself via
Applescript, it successfully adds the contents of cb.txt to the
clipboard):
set the_file to "HardDrive:Users:Me:Dropbox:Folder:cb.txt"
set the_text to (do shell script "cat " & quoted form of (POSIX path of
the_file))
set the clipboard to the_text
I have saved this file to ~/Library/Application
Scripts/com.Growl.GrowlHelperApp as an apple script. I have also saved
another version using this code:
using terms from application "Growl"
on perform action with notification
ignoring case
if notification's app name is Dropbox then
if notification's note title contains "cb.txt added" then
set the_file to "Macintosh
HD:Users:Caleb:Dropbox:Apps:CBApp:cb.txt"
set the_text to (do shell script "cat " & quoted form
of (POSIX path of the_file))
set the clipboard to the_text
end if
end if
end ignoring
end perform action
end using terms from
The previous script does not do anything when run. I have this saved as
Rules.scpt:
using terms from application "Growl"
on evaluate notification with notification
--Rules go in here
--Ultimately return what you want Growl to do with the notification
end evaluate notification
end using terms from
Obviously, I'm a bit stuck. If anybody could give me advice on how to get
my working applescript code to run when I receive a specific Growl
notification, I would appreciate it!
Currently, I have a flow set up that results in a file -- 'cb.txt' --
being added to my Dropbox. I get a Growl notification with the Application
Name 'Dropbox' and the Note Title 'cb.txt added'. I want the 'cb.txt
added' notification to run an applescript that will copy the text from
cb.txt to my clipboard. The rules for Growl's notification can be found
here.
Here is the applescript I want to run (when I run it by itself via
Applescript, it successfully adds the contents of cb.txt to the
clipboard):
set the_file to "HardDrive:Users:Me:Dropbox:Folder:cb.txt"
set the_text to (do shell script "cat " & quoted form of (POSIX path of
the_file))
set the clipboard to the_text
I have saved this file to ~/Library/Application
Scripts/com.Growl.GrowlHelperApp as an apple script. I have also saved
another version using this code:
using terms from application "Growl"
on perform action with notification
ignoring case
if notification's app name is Dropbox then
if notification's note title contains "cb.txt added" then
set the_file to "Macintosh
HD:Users:Caleb:Dropbox:Apps:CBApp:cb.txt"
set the_text to (do shell script "cat " & quoted form
of (POSIX path of the_file))
set the clipboard to the_text
end if
end if
end ignoring
end perform action
end using terms from
The previous script does not do anything when run. I have this saved as
Rules.scpt:
using terms from application "Growl"
on evaluate notification with notification
--Rules go in here
--Ultimately return what you want Growl to do with the notification
end evaluate notification
end using terms from
Obviously, I'm a bit stuck. If anybody could give me advice on how to get
my working applescript code to run when I receive a specific Growl
notification, I would appreciate it!
Flot Bar Graph Align Bars with X-Axis Labels
Flot Bar Graph Align Bars with X-Axis Labels
Hello I am trying to plot a bar chart with 31 days data. However when I
plot it, the label for each data is not directly in the center below its
bar, when i set the bars to
align: "center"
, the first bar and last bar gets cut into half.
Here is the jsfiddle: http://jsfiddle.net/3T6qc/
How do I set it so that i see the full bars and have the labels directly
below in the center? Take note that I am using flot as the plotting
library.
Hello I am trying to plot a bar chart with 31 days data. However when I
plot it, the label for each data is not directly in the center below its
bar, when i set the bars to
align: "center"
, the first bar and last bar gets cut into half.
Here is the jsfiddle: http://jsfiddle.net/3T6qc/
How do I set it so that i see the full bars and have the labels directly
below in the center? Take note that I am using flot as the plotting
library.
Create DetailsView from codebehind
Create DetailsView from codebehind
I'm new to Asp.net and have looked around for how to do this, but haven't
been able to find it.
I would like to create a detailsview entirely from codebehind. This is
because I need certain fields to load based on the user's permissions.
Also, I would like the ability to edit the detailsview to be only
accessible to certain users. Is there a way to do this?
I'm new to Asp.net and have looked around for how to do this, but haven't
been able to find it.
I would like to create a detailsview entirely from codebehind. This is
because I need certain fields to load based on the user's permissions.
Also, I would like the ability to edit the detailsview to be only
accessible to certain users. Is there a way to do this?
Different types of lists
Different types of lists
Hello I am studying Java and I am just confused about a question that
keeps coming up in my exams.
We are told to use a class for our collections.
Usually in my main class I just make an arraylist of the type I need like
bank accounts or whatever. But I think we are supposed to make a class for
all our data. I tried this and made them static and have the class
abstract because I don't need to make copies of the class itself.
What I want to know is why don't people just make a list type that can do
everything an arraylist and list can do in one, why is there different
types? What are the benifits of having different types? Ps does a
collection just mean a class for all your data?
Hello I am studying Java and I am just confused about a question that
keeps coming up in my exams.
We are told to use a class for our collections.
Usually in my main class I just make an arraylist of the type I need like
bank accounts or whatever. But I think we are supposed to make a class for
all our data. I tried this and made them static and have the class
abstract because I don't need to make copies of the class itself.
What I want to know is why don't people just make a list type that can do
everything an arraylist and list can do in one, why is there different
types? What are the benifits of having different types? Ps does a
collection just mean a class for all your data?
Google Chrome selects whole column if I want to select a row
Google Chrome selects whole column if I want to select a row
Whenever I try to select a row, Google Chrome select the entire column. If
I press CTRL+C (CMD+C) and CTRL+V (CMD+V), only the row -just as expected-
is copied/inserted.
It works fine on Firefox, Safari and Opera:
You can view a life-example by visiting Metahill and joining as Guest.
Whenever I try to select a row, Google Chrome select the entire column. If
I press CTRL+C (CMD+C) and CTRL+V (CMD+V), only the row -just as expected-
is copied/inserted.
It works fine on Firefox, Safari and Opera:
You can view a life-example by visiting Metahill and joining as Guest.
Subscribe to:
Posts (Atom)