-
Notifications
You must be signed in to change notification settings - Fork 7
/
DetermineMixtureParameters.h
62 lines (49 loc) · 2.15 KB
/
DetermineMixtureParameters.h
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
60
61
62
#pragma once
#include <opencv2\opencv.hpp>
#include "RayleighMixtureData.h"
#include "RayleighMixtureCostFunction.h"
#include "AdaptiveSimulatedAnnealing.h"
using namespace std;
using namespace cv;
class DetermineMixtureParameters {
public:
template<typename T>
static void set(RayleighMixtureData& rayleighMixtureData, int minimumMixtureCount)
{
if (rayleighMixtureData.dimension == 1) {
// single Rayleigh
pair<double, double> estimation = rayleighMixtureData.estimateSigmaSqr(0, rayleighMixtureData.histogramSize - 1);
const double phatSqr = estimation.first;
rayleighMixtureData.Weights[0] = 1.0;
rayleighMixtureData.Sigmas[0] = sqrt(phatSqr);
rayleighMixtureData.sqrSigmas[0] = phatSqr;
rayleighMixtureData.intervalCount = 1;
rayleighMixtureData.intervals[0] = 0;
rayleighMixtureData.intervals[1] = 50; // a dummy number between 1 and 99 --> resulting interval is [0, 100]
rayleighMixtureData.intervals[2] = 100;
rayleighMixtureData.initialError = 0.0;
rayleighMixtureData.finalError = 0.0;
rayleighMixtureData.iterationCount = 0;
}
else {
// mixture of Rayleigh
const double lowerBoundPercentage = 1.0;
const double upperBoundPercentage = 99.0;
RayleighMixtureCostFunction<T> rmCostFunction(rayleighMixtureData, minimumMixtureCount);
rmCostFunction.setLowerBound(lowerBoundPercentage);
rmCostFunction.setUpperBound(upperBoundPercentage);
Mat x(rayleighMixtureData.dimension, 1, CV_64FC1, Scalar(0));
double* x_initial = (double*)x.data;
rmCostFunction.initializeX0(x_initial);
rayleighMixtureData.initialError = rmCostFunction.evaluate(x_initial);
const double initialTemperature = 250;
const int iterationPerDimension = 1000;
const double convergenceTolerance = 1e-4;
AdaptiveSimulatedAnnealing asa(initialTemperature, iterationPerDimension, convergenceTolerance);
SAOptimimumSolution optimimumSolution = asa.minimize(rmCostFunction, x_initial);
rayleighMixtureData.finalError = rmCostFunction.evaluate(optimimumSolution.x_optimum);
rayleighMixtureData.iterationCount = optimimumSolution.iteration;
}
}
private:
};