use named structs in small algebra system.
This commit is contained in:
parent
a4fdbc1e2c
commit
79dfcf79db
|
@ -341,4 +341,10 @@ It emits one warning about something I already took care of, so by default I've
|
||||||
- [x] Have some more complicated & realistic example
|
- [x] Have some more complicated & realistic example
|
||||||
- [x] Add summarization functions: 90% ci (or all c.i.?)
|
- [x] Add summarization functions: 90% ci (or all c.i.?)
|
||||||
- [x] Link to the examples in the examples section.
|
- [x] Link to the examples in the examples section.
|
||||||
- [x] Add a few functions for doing simple algebra on normals, and lognormals?
|
- [x] Add a few functions for doing simple algebra on normals, and lognormals
|
||||||
|
- [x] Add prototypes
|
||||||
|
- [x] Use named structs
|
||||||
|
- [ ] Test results
|
||||||
|
- [ ] Provide example
|
||||||
|
- [ ] Add to headers
|
||||||
|
- [ ] Move to own file
|
||||||
|
|
24
squiggle.c
24
squiggle.c
|
@ -437,44 +437,44 @@ struct c_i get_90_confidence_interval(double (*sampler)(uint64_t*), uint64_t* se
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do algebra over lognormals and normals
|
// Do algebra over lognormals and normals
|
||||||
struct normal_parameters {
|
typedef struct {
|
||||||
double mean;
|
double mean;
|
||||||
double std;
|
double std;
|
||||||
};
|
} normal_parameters;
|
||||||
|
|
||||||
struct lognormal_parameters {
|
struct {
|
||||||
double logmean;
|
double logmean;
|
||||||
double logstd;
|
double logstd;
|
||||||
};
|
} lognormal_parameters;
|
||||||
|
|
||||||
struct normal_parameters algebra_sum_normals(struct normal_parameters a, struct normal_parameters b)
|
normal_parameters algebra_sum_normals(normal_parameters a, normal_parameters b)
|
||||||
{
|
{
|
||||||
struct normal_parameters result = {
|
normal_parameters result = {
|
||||||
.mean = a.mean + b.mean,
|
.mean = a.mean + b.mean,
|
||||||
.std = sqrt((a.std * a.std) + (b.std * b.std)),
|
.std = sqrt((a.std * a.std) + (b.std * b.std)),
|
||||||
};
|
};
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
struct normal_parameters algebra_shift_normal(struct normal_parameters a, double shift)
|
normal_parameters algebra_shift_normal(normal_parameters a, double shift)
|
||||||
{
|
{
|
||||||
struct normal_parameters result = {
|
normal_parameters result = {
|
||||||
.mean = a.mean + shift,
|
.mean = a.mean + shift,
|
||||||
.std = a.std,
|
.std = a.std,
|
||||||
};
|
};
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct lognormal_parameters algebra_product_lognormals(struct lognormal_parameters a, struct lognormal_parameters b)
|
lognormal_parameters algebra_product_lognormals(lognormal_parameters a, lognormal_parameters b)
|
||||||
{
|
{
|
||||||
struct lognormal_parameters result = {
|
lognormal_parameters result = {
|
||||||
.logmean = a.logmean + b.logmean,
|
.logmean = a.logmean + b.logmean,
|
||||||
.logstd = sqrt((a.logstd * a.logstd) + (b.logstd * b.logstd)),
|
.logstd = sqrt((a.logstd * a.logstd) + (b.logstd * b.logstd)),
|
||||||
};
|
};
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
struct lognormal_parameters algebra_scale_lognormal(struct lognormal_parameters a, double k)
|
lognormal_parameters algebra_scale_lognormal(lognormal_parameters a, double k)
|
||||||
{
|
{
|
||||||
struct lognormal_parameters result = {
|
lognormal_parameters result = {
|
||||||
.logmean = a.logmean + k,
|
.logmean = a.logmean + k,
|
||||||
.logstd = a.logstd,
|
.logstd = a.logstd,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user