-
Notifications
You must be signed in to change notification settings - Fork 3
/
step_function.hpp
executable file
·59 lines (50 loc) · 2.32 KB
/
step_function.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef STEPFN_HPP
#define STEPFN_HPP
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <cfloat>
#include <cstdlib>
#include <cassert>
#include <vector>
#include "univariate_function.hpp"
#include "Data.hpp"
#define GSL_RANGE_CHECK_OFF
using namespace std;
class Step_Function : public Univariate_Function
{
public:
Step_Function(double* knots, double* heights, unsigned int num_knots, double end = DBL_MAX, bool do_cumulative = true);
Step_Function(vector<double>* knots, vector<double>* heights, double end = DBL_MAX, bool do_cumulative = true);
Step_Function(const string input_filename, double end = DBL_MAX, bool do_cumulative = true);
Step_Function( const Step_Function* f );
~Step_Function();
void construct_step_function(vector<double>* knots, vector<double>* heights, double end, bool do_cumulative);
void calculate_cumulative_function();
unsigned int find_position_in_knots( double t, bool bisection = false, unsigned int l = 0, unsigned int h = 0 );
virtual double function( double t );
virtual double cumulative_function( double t );
virtual double cumulative_function( double s, double t );
double get_end_cumulative(){ return m_end_cumulative; }
double* get_changepoints(){ return m_knots; }
double* get_heights(){ return m_heights; }
double* get_cumulative_heights(){ return m_cumulative; }
unsigned int get_num_changepoints(){ return m_num_knots; }
Step_Function* combine_with_step_function( Step_Function* f, bool multiply = true );
Step_Function* add_step_function( Step_Function* f ){ return combine_with_step_function( f, false ); };
Step_Function* multiply_step_function( Step_Function* f ){ return combine_with_step_function( f, true ); };
void scale_step_function(double);
void standardise_step_function(){ scale_step_function(1/m_end_cumulative); }
double get_end(){ return m_end; }
friend ostream& operator<< ( ostream& os, Step_Function* & f );
vector<unsigned int>* find_data_segments( Data<double>* D );
protected:
double* m_knots;//assume in increasing order
double* m_heights;
double m_end;//after this value, the step function gets repeated, infinitely.
double m_end_cumulative;//the integral of the step function up to m_end
double* m_cumulative;//the integral of the step function up to each knot point
unsigned int m_num_knots;
};
#endif