Skip to content

Commit

Permalink
added script to calculate the correlation integral of a large number …
Browse files Browse the repository at this point in the history
…of points in an iterative and statistical fashion, documentation to follow
  • Loading branch information
Jacob Perkins committed Jul 10, 2010
1 parent c13ea83 commit 8465171
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 928 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--
-- Correlation Integral
--
-- C(e) = lim N->inf (1/N^2)*SUM( H( e - distance(x_i,x_j) ) )
--
-- where H is the Heaviside step function { 0 if distance(x_i,x_j) > e, 1 if distance(x_i,x_j) < e }
-- where x_i and x_j are different points on the attractor
--
-- Here we take a sample n < N to calculate it for a given e (EPS)
--
REGISTER /usr/local/share/pig/contrib/piggybank/java/piggybank.jar;
%default ATTRACTOR 'data/points.tsv'
%default SAMPLE_FRAC '0.1' -- higher precentage = better accuracy but slower and more intensive
%default SAMPLE_SIZE '100' -- should be less than or equal to what is pulled out from the SAMPLE command
%default EPS '0.5' -- independent variable in the correlation integral
%default OUT 'data/corr_iter_00'

attractor = LOAD '$ATTRACTOR' AS (x1:double, x2:double);
first = SAMPLE attractor $SAMPLE_FRAC;
second = SAMPLE attractor $SAMPLE_FRAC;
sample_1 = LIMIT first $SAMPLE_SIZE;
sample_2 = LIMIT second $SAMPLE_SIZE;
crossed = CROSS sample_1, sample_2; -- careful
dists = FOREACH crossed
{
sq_dist = (sample_1::x1 - sample_2::x1)*(sample_1::x1 - sample_2::x1) + (sample_1::x2 - sample_2::x2)*(sample_1::x2 - sample_2::x2);
GENERATE org.apache.pig.piggybank.evaluation.math.SQRT(sq_dist) AS dist;
};
to_sum = FILTER dists BY dist < $EPS;
grouped = GROUP to_sum ALL;
corr = FOREACH grouped GENERATE (float)SIZE(to_sum)/((float)$SAMPLE_SIZE*(float)$SAMPLE_SIZE) AS corr_val, $EPS AS eps;;

rmf $OUT;
STORE corr INTO '$OUT';
18 changes: 18 additions & 0 deletions analysis/dynamical_systems/correlation_integral/henon_map.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env ruby

def henon_map
steps = 1000000
a = 1.4
b = 0.3
x = 0.631354477
y = 0.189406343

steps.times do
x_old = x
x = y + 1 - a*x*x
y = b*x_old
puts [x,y].join("\t") + "\n"
end
end

henon_map
28 changes: 28 additions & 0 deletions analysis/dynamical_systems/correlation_integral/iterate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env ruby

#
# Pass these in via args
#
raise "\n\nUsage: ./iterate.rb /path/to/attractor <num_iters> /path/to/output_dir\n" unless ARGV.length == 3
attractor = ARGV[0]
num_iters = ARGV[1]
work_dir = ARGV[2]

#
# Parameters that are constant throughout the calculation
#
eps_min = 0.001
eps_increment = 0.025
sample_size = 5000
sample_fraction = 0.001

iter = 0
eps = eps_min
num_iters.to_i.times do
next_file = "corr_iter_" + iter.to_s
next_dir = File.join(work_dir, next_file)
system %Q{ pig -param ATTRACTOR=#{attractor} -param OUT=#{next_dir} -param EPS=#{eps} -param SAMPLE_SIZE=#{sample_size} -param SAMPLE_FRAC=#{sample_fraction} correlation_integral.pig }
iter += 1
eps += eps_increment
end

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ for (( curr=0 , next=1 ; "$curr" < "$num_iters" ; curr++ , next++ )) ; do
next_str=`printf "%03d" ${next}`
curr_dir=${work_dir}/pagerank_graph_${curr_str}
next_dir=${work_dir}/pagerank_graph_${next_str}
pig -x local -param PRGRPH="${curr_dir}" -param OUT="${next_dir}" pagerank.pig
# pig -param PRGRPH="${curr_dir}" -param OUT="${next_dir}" pagerank.pig
# pig -x local -param PRGRPH="${curr_dir}" -param OUT="${next_dir}" pagerank.pig
pig -param PRGRPH="${curr_dir}" -param OUT="${next_dir}" pagerank.pig
done

File renamed without changes.
File renamed without changes.
26 changes: 0 additions & 26 deletions generic/chaos.pig

This file was deleted.

Loading

0 comments on commit 8465171

Please sign in to comment.