Skip to content
Snippets Groups Projects
Commit 8f824a8a authored by podlesny's avatar podlesny
Browse files

python based data analysis

parent f2c3cc41
No related branches found
No related tags found
No related merge requests found
Showing
with 126 additions and 36 deletions
import numpy as np
def maximum(x):
size = x.shape
res = np.zeros(size[0])
for time_step in range(size[0]):
res[time_step] = max(res[time_step], max(x[time_step, :]))
return res
File added
import numpy as np
def maximum(x) :
size = x.shape
res = np.zeros(size[0])
for time_step in range(size[0]) :
for vertex in range(size[1]) :
res[time_step] = max(res[time_step], max(x[time_step, vertex]))
return res
\ No newline at end of file
#include <Rcpp.h>
// [[Rcpp::export]]
Rcpp::NumericVector negativeStarts(Rcpp::NumericVector const &x) {
std::vector<size_t> starts(0);
bool prev = false;
for (size_t i = 0; i < x.size(); ++i) {
if (prev && !x[i])
starts.push_back(i+1); // R indices start at 1
prev = x[i];
}
return Rcpp::NumericVector(starts.begin(), starts.end());
}
import numpy as np
def norm(x):
size = x.shape
res = np.zeros((size[0], size[1]))
for time_step in range(size[0]):
for vertex in range(size[1]):
res[time_step, vertex] = np.linalg.norm(x[time_step, vertex, :])
return res
File added
import numpy as np
def norm(x) :
size = x.shape
res = np.zeros(size[0], size[1])
for time_step in range(size[0]) :
for vertex in range(size[1]) :
res[time_step, vertex] = np.linalg.norm(x[time_step, vertex, :])
return res
#include <Rcpp.h>
// [[Rcpp::export]]
Rcpp::NumericVector positiveStarts(Rcpp::NumericVector const &x) {
std::vector<size_t> starts(0);
bool prev = false;
for (size_t i = 0; i < x.size(); ++i) {
if (!prev && x[i])
starts.push_back(i+1); // R indices start at 1
prev = x[i];
}
return Rcpp::NumericVector(starts.begin(), starts.end());
}
import array as ar
def slip_beginnings(x):
# returns indicies i for which x[i-1]=0 and x[i]>0
starts = ar.array('i', (0 for i in range(len(x))))
prev = False
length = 0
for i in range(len(x)):
if (not prev and x[i]):
starts[length] = i
length += 1
prev = x[i]
return starts[:length]
File added
import numpy as np
def slip_beginnings(x) :
# returns indicies i for which x[i-1]=0 and x[i]>0
starts = []
prev = False
for i in range(len(x)) :
if (not prev and x[i]) :
starts.append(i)
prev = x[i]
return starts
import array as ar
def slip_endings(x):
# returns indicies i for which x[i-1]>0 and x[i]=0
ends = ar.array('i', (0 for i in range(len(x))))
prev = False
length = 0
for i in range(len(x)):
if (prev and not x[i]):
ends[length] = i
length += 1
prev = x[i]
return ends[:length]
File added
import numpy as np
def slip_endings(x) :
# returns indicies i for which x[i-1]>0 and x[i]=0
starts = np.array([])
prev = False
for i in range(len(x)) :
if (prev and not x[i]) :
starts.append(i)
prev = x[i]
return starts
\ No newline at end of file
#include <Rcpp.h>
// [[Rcpp::export]]
double trapezoidal(Rcpp::NumericVector const &x, Rcpp::NumericVector const &y) {
double ret = 0;
for (size_t i = 1; i < x.size(); ++i)
ret += (x[i] - x[i - 1]) * (y[i] + y[i - 1]) / 2;
return ret;
}
# x: vector of domain values
# y: vector of function values f(x)
def trapezoidal(x, y) :
# returns integral of (x, y = f(x)) calculated with trapezoidal rule
res = 0.0
for i in range(1, len(x)) :
res += (x[i] - x[i - 1]) * (y[i] + y[i - 1]) / 2.0
return res
\ No newline at end of file
# x: vector of domain values
# y: vector of function values f(x)
def trapezoidal(x, y) :
# returns integral of (x, y = f(x)) calculated with trapezoidal rule
res = 0.0
for i in range(1, len(x)) :
res += (x[i] - x[i - 1]) * (y[i] + y[i - 1]) / 2.0
return res
\ No newline at end of file
% householder reflection
v0 = [1; 0];
v0 = v0./norm(v0);
v1 = [1; -1];
v1 = v1./norm(v1);
v = 1/2.*(v1-v0);
vnorm = norm(v);
H = eye(2) - 2/(vnorm^2).*(v*v')
A = [...
];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment