commit c1c37f0c56b6bdd680c393f41f843ffb25fe1d11
parent 7b33f058c273c8173e20d44f6b3e44a1a561b86d
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 1 Apr 2015 11:45:33 +0200
Rename the fields of the smc_estimator_status structure
Diffstat:
3 files changed, 26 insertions(+), 38 deletions(-)
diff --git a/src/smc.h b/src/smc.h
@@ -71,10 +71,10 @@ struct smc_type {
};
struct smc_estimator_status {
- void* expected_value;
- void* variance;
- void* standard_error;
- unsigned long samples_count;
+ void* E; /* Expected value */
+ void* V; /* Variance */
+ void* SE; /* Standard error, i.e. sqrt(V / N) */
+ unsigned long N; /* Samples count */
};
static const struct smc_type smc_type_null =
diff --git a/src/smc_integrator.c b/src/smc_integrator.c
@@ -65,12 +65,12 @@ estimator_release(ref_T* ref)
MEM_FREE(dev->allocator, estimator->value);
if(estimator->square_value)
MEM_FREE(dev->allocator, estimator->square_value);
- if(estimator->status.expected_value)
- MEM_FREE(dev->allocator, estimator->status.expected_value);
- if(estimator->status.variance)
- MEM_FREE(dev->allocator, estimator->status.variance);
- if(estimator->status.standard_error)
- MEM_FREE(dev->allocator, estimator->status.standard_error);
+ if(estimator->status.E)
+ MEM_FREE(dev->allocator, estimator->status.E);
+ if(estimator->status.V)
+ MEM_FREE(dev->allocator, estimator->status.V);
+ if(estimator->status.SE)
+ MEM_FREE(dev->allocator, estimator->status.SE);
MEM_FREE(dev->allocator, estimator);
SMC(device_ref_put(dev));
}
@@ -115,13 +115,13 @@ smc_solve
} (void)0
TYPE_CREATE(estimator->value);
TYPE_CREATE(estimator->square_value);
- TYPE_CREATE(estimator->status.expected_value);
- TYPE_CREATE(estimator->status.variance);
- TYPE_CREATE(estimator->status.standard_error);
+ TYPE_CREATE(estimator->status.E);
+ TYPE_CREATE(estimator->status.V);
+ TYPE_CREATE(estimator->status.SE);
TYPE_CREATE(val);
#undef TYPE_CREATE
estimator->nsamples = 0;
- estimator->status.samples_count = 0;
+ estimator->status.N = 0;
estimator->type = *type;
FOR_EACH(i, 0, 4096) {
@@ -169,36 +169,26 @@ smc_estimator_get_status
if(!estimator || !status)
return RES_BAD_ARG;
- if(estimator->nsamples != estimator->status.samples_count) {
- estimator->status.samples_count = estimator->nsamples;
+ if(estimator->nsamples != estimator->status.N) {
+ estimator->status.N = estimator->nsamples;
/* Variance */
estimator->type.divi
- (estimator->status.expected_value,
- estimator->square_value,
- estimator->nsamples);
+ (estimator->status.E, estimator->square_value, estimator->nsamples);
estimator->type.mul
- (estimator->status.variance, estimator->value, estimator->value);
+ (estimator->status.V, estimator->value, estimator->value);
estimator->type.divi
- (estimator->status.variance,
- estimator->status.variance,
+ (estimator->status.V,
+ estimator->status.V,
estimator->nsamples * estimator->nsamples);
estimator->type.sub
- (estimator->status.variance,
- estimator->status.expected_value,
- estimator->status.variance);
+ (estimator->status.V, estimator->status.E, estimator->status.V);
/* Standard error */
estimator->type.divi
- (estimator->status.standard_error,
- estimator->status.variance,
- estimator->nsamples);
- estimator->type.sqrt
- (estimator->status.standard_error,
- estimator->status.standard_error);
+ (estimator->status.SE, estimator->status.V, estimator->nsamples);
+ estimator->type.sqrt(estimator->status.SE, estimator->status.SE);
/* Expected value */
estimator->type.divi
- (estimator->status.expected_value,
- estimator->value,
- estimator->nsamples);
+ (estimator->status.E, estimator->value, estimator->nsamples);
}
*status = estimator->status;
return RES_OK;
diff --git a/src/test_smc_solve.c b/src/test_smc_solve.c
@@ -95,15 +95,13 @@ main(int argc, char** argv)
CHECK(smc_estimator_get_status(estimator, &status), RES_OK);
CHECK(eq_eps
((float)(log(2.f) - log(1.f)),
- SMC_FLOAT(status.expected_value),
- SMC_FLOAT(status.standard_error)), 1);
+ SMC_FLOAT(status.E), SMC_FLOAT(status.SE)), 1);
CHECK(smc_estimator_ref_put(estimator), RES_OK);
CHECK(smc_solve(dev, cos_x, &smc_float, (void*)0xC0DE, &estimator), RES_OK);
CHECK(eq_eps
((float)(sin(3.0*PI/4.0) - sin(PI/4.0)),
- SMC_FLOAT(status.expected_value),
- SMC_FLOAT(status.standard_error)), 1);
+ SMC_FLOAT(status.E), SMC_FLOAT(status.SE)), 1);
CHECK(smc_device_ref_put(dev), RES_OK);
CHECK(smc_estimator_ref_put(estimator), RES_OK);