Repository navigation
Expand file tree
/
Copy pathSolutionFile.c
More file actions
592 lines (583 loc) · 31 KB
/
Copy pathSolutionFile.c
File metadata and controls
592 lines (583 loc) · 31 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
// CLASCAL (SolutionFile.c)
//
// Copyright (c) 2010 by John Ashley Burgoyne and the Royal Institute for the
// Advancement of Learning (McGill University). All rights reserved.
//
// This source is adapted from Suzanne Winsberg's CLASCAL, version 7.01 (May
// 1993), written in FORTRAN 77.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions, and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions, and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of McGill University nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "inlines.h"
#include "jansson.h"
#include "StimulusSet.h"
#include "SubjectSet.h"
#include "Experiment.h"
#include "Model.h"
#include "ClassAssignment.h"
#include "ModelSpace.h"
#include "_ModelSpace.h"
#include "Solution.h"
#include "_Solution.h"
static json_t * json_null_or_real(double d)
{
switch (fpclassify(d)) {
case FP_NORMAL:
return json_real(d);
case FP_SUBNORMAL:
if (!signbit(d)) return json_real(DBL_MIN);
else return json_real(-DBL_MIN);
case FP_ZERO:
if (!signbit(d)) return json_real(0.0);
else return json_real(-0.0);
case FP_INFINITE:
if (!signbit(d)) return json_real(DBL_MAX);
else return json_real(-DBL_MAX);
default:
return json_null();
}
}
static json_t * json_array_with_vector(const double * restrict vector,
size_t length,
size_t stride)
{
json_t * restrict array = json_array();
for (size_t i = 0; i < SizeProduct(length, stride); i += stride)
json_array_append_new(array, json_null_or_real(vector[i]));
return array;
}
/* N.B. This function leaks memory when loading the parameters and the model. */
static Solution * NewSolutionFromJSON(const json_t * restrict solutionJSON,
const Experiment * restrict experiment)
{
// There are few checks for type in this function because Jansson
// returns NULL on error and NULL parameters simply yield a NULL
// Solution.
const StimulusSet * restrict stimulusSet = NULL;
stimulusSet = ExperimentStimulusSet(experiment);
const json_t * restrict coordinatesJSON = NULL;
coordinatesJSON = json_object_get(solutionJSON, "Coordinates");
const json_t * restrict stimulusJSON = NULL;
stimulusJSON = json_object_get(coordinatesJSON,
StimulusNameForIndex(stimulusSet, 0));
const size_t dimensionCount = json_array_size(stimulusJSON);
const SubjectSet * restrict subjectSet = NULL;
subjectSet = ExperimentSubjectSet(experiment);
const json_t * restrict posteriorsJSON = NULL;
posteriorsJSON = json_object_get(solutionJSON,
"PosteriorProbabilities");
const json_t * restrict subjectJSON = NULL;
subjectJSON = json_object_get(posteriorsJSON,
SubjectNameForIndex(subjectSet, 0));
const size_t classCount = json_array_size(subjectJSON);
const json_t * restrict specificitiesJSON = NULL;
specificitiesJSON = json_object_get(solutionJSON, "Specificities");
const json_t * restrict specJSON = NULL;
specJSON = json_object_get(specificitiesJSON,
StimulusNameForIndex(stimulusSet, 0));
const SpecificityType specType = (specificitiesJSON
? (json_is_number(specJSON)
? GlobalSpecificities
: ClassSpecificities)
: NoSpecificities);
// N.B. This Model will never be deleted.
Model * restrict model = NewModel(dimensionCount, classCount, specType);
const size_t subjectCount = SubjectCount(subjectSet);
const size_t distributionsSize = SizeProduct(subjectCount, classCount);
double * restrict distributions = NULL;
distributions = SafeMalloc(distributionsSize, sizeof(double));
for (size_t i = 0; i < subjectCount; i++) {
const char * subjectName = SubjectNameForIndex(subjectSet, i);
subjectJSON = json_object_get(posteriorsJSON, subjectName);
for (size_t t = 0; t < classCount; t++) {
const json_t * restrict valueJSON = NULL;
valueJSON = json_array_get(subjectJSON, t);
const double value = json_number_value(valueJSON);
distributions[classCount * i + t] = value;
}
}
ClassAssignment * restrict assignment = NULL;
assignment = NewClassAssignment(subjectSet, model, distributions);
FreeAndClear(distributions);
const size_t weightsLength = ((specType == GlobalSpecificities)
? SizeSum(dimensionCount, 1)
: dimensionCount);
const size_t weightsSize = SizeProduct(weightsLength, classCount);
double * restrict weights = NULL;
if (classCount > 1 && (dimensionCount > 0 || specType)) {
weights = SafeMalloc(weightsSize, sizeof(double));
const json_t * restrict weightsJSON = NULL;
weightsJSON = json_object_get(solutionJSON, "Weights");
for (size_t t = 0; t < classCount; t++) {
const json_t * restrict classJSON = NULL;
classJSON = json_array_get(weightsJSON, t);
for (size_t r = 0; r < weightsLength; r++) {
const json_t * restrict valJSON = NULL;
valJSON = json_array_get(classJSON, r);
const double value = json_number_value(valJSON);
weights[classCount * r + t] = value;
}
}
}
const size_t stimulusCount = StimulusCount(stimulusSet);
const size_t coordinatesSize = SizeProduct(stimulusCount,
dimensionCount);
double * restrict coordinates = NULL;
if (dimensionCount > 0) {
coordinates = SafeMalloc(coordinatesSize, sizeof(double));
for (size_t j = 0; j < stimulusCount; j++) {
const char * stName = NULL;
stName = StimulusNameForIndex(stimulusSet, j);
stimulusJSON = json_object_get(coordinatesJSON, stName);
for (size_t r = 0; r < dimensionCount; r++) {
const json_t * restrict valJSON = NULL;
valJSON = json_array_get(stimulusJSON, r);
const double value = json_number_value(valJSON);
coordinates[dimensionCount * j + r] = value;
}
}
}
double * restrict specificities = NULL;
switch (specType) {
case ClassSpecificities:
specificities = SafeMalloc(SizeProduct(classCount,
stimulusCount),
sizeof(double));
for (size_t j = 0; j < stimulusCount; j++) {
const char * stimName = NULL;
stimName = StimulusNameForIndex(stimulusSet, j);
specJSON = json_object_get(specificitiesJSON,
stimName);
for (size_t t = 0; t < classCount; t++) {
const json_t * restrict valJSON = NULL;
valJSON = json_array_get(specJSON, t);
const double value
= json_number_value(valJSON);
specificities[stimulusCount * t + j]
= value;
}
}
break;
case GlobalSpecificities:
specificities = SafeMalloc(stimulusCount,
sizeof(double));
for (size_t j = 0; j < stimulusCount; j++) {
const char * stimName = NULL;
stimName = StimulusNameForIndex(stimulusSet, j);
specJSON = json_object_get(specificitiesJSON,
stimName);
const double value
= json_number_value(specJSON);
specificities[j] = value;
}
break;
default:
// Leave specificities NULL.
break;
}
const size_t pairCount = StimulusPairCount(stimulusSet);
const size_t distancesSize = SizeProduct(subjectCount, pairCount);
ModelSpace * space = NULL;
if (dimensionCount || specificities) {
space = NewModelSpace(stimulusSet,
model,
weights,
coordinates,
specificities);
} else {
double * distances = SafeMalloc(distancesSize, sizeof(double));
const json_t * restrict dissJSON = NULL;
dissJSON = json_object_get(solutionJSON,
"PredictedDissimilarities");
for (size_t t = 0; t < classCount; t++) {
const json_t * restrict classJSON = NULL;
classJSON = json_array_get(dissJSON,
(unsigned int)t);
size_t m = 0;
for (size_t j = 0; j < stimulusCount - 1; j++) {
const json_t * restrict line = NULL;
line = json_array_get(classJSON,
(unsigned int)j);
for (size_t k = 0; k < j + 1; k++) {
const json_t * restrict datum = NULL;
datum = json_array_get(line,
(unsigned int)k);
double d = NAN;
if (json_is_real(datum)) {
d = json_real_value(datum);
} else if (json_is_integer(datum)) {
d = (double)json_integer_value(datum);
} else if (json_is_null(datum)) {
d = NAN;
} else {
ExitWithError("Some"
" dissimilarities"
" are missing");
}
distances[pairCount * t + m++] = d;
}
}
}
space = NewDummySpace(stimulusSet, model, distances);
}
FreeAndClear(specificities);
FreeAndClear(coordinates);
FreeAndClear(weights);
const json_t * restrict priorJSON = NULL;
priorJSON = json_object_get(solutionJSON, "PriorDistribution");
double * restrict prior = SafeMalloc(classCount, sizeof(double));
for (size_t t = 0; t < classCount; t++)
prior[t] = json_number_value(json_array_get(priorJSON, t));
const json_t * restrict estimatedVarianceJSON = NULL;
estimatedVarianceJSON = json_object_get(solutionJSON,
"EstimatedVariance");
const double sigmaSquared = json_number_value(estimatedVarianceJSON);
const json_t * restrict parametersJSON = NULL;
parametersJSON = json_object_get(solutionJSON, "Parameters");
// N.B. This Parameters object will never be freed.
Parameters * parameters = SafeMalloc(1, sizeof(Parameters));
// Verbosity is not saved in the file and defaults to zero.
parameters->verbosity = SILENT;
const json_t * restrict useTorgersonStartJSON = NULL;
useTorgersonStartJSON = json_object_get(parametersJSON,
"TorgersonStart");
parameters->useTorgersonStart = (json_is_true(useTorgersonStartJSON)
? true
: false);
const json_t * restrict useKMeansStartJSON = NULL;
useKMeansStartJSON = json_object_get(parametersJSON,
"KMeansStart");
parameters->useKMeansStart = (json_is_true(useKMeansStartJSON)
? true
: false);
parameters->maxEMIterationCount
= json_integer_value(json_object_get(parametersJSON,
"MaxEMIterationCount"));
parameters->EMImprovementAmount
= json_real_value(json_object_get(parametersJSON,
"EMImprovementAmount"));
parameters->maxMIterationCount
= json_integer_value(json_object_get(parametersJSON,
"MaxMIterationCount"));
parameters->MImprovementFactor
= json_real_value(json_object_get(parametersJSON,
"MImprovementFactor"));
parameters->maxSpatialIterationCount
= json_integer_value(json_object_get(parametersJSON,
"MaxSpatialIterationCount"));
parameters->minSpecificityValue
= json_real_value(json_object_get(parametersJSON,
"MinSpecificityValue"));
parameters->spatialImprovementFactor
= json_real_value(json_object_get(parametersJSON,
"SpatialImprovementFactor"));
parameters->maxWeightIterationCount
= json_integer_value(json_object_get(parametersJSON,
"MaxWeightIterationCount"));
parameters->minWeightValue
= json_real_value(json_object_get(parametersJSON,
"MinWeightValue"));
parameters->weightImprovementFactor
= json_real_value(json_object_get(parametersJSON,
"WeightImprovementFactor"));
parameters->maxSearchIterationCount
= json_integer_value(json_object_get(parametersJSON,
"MaxSearchIterationCount"));
parameters->firstStepSize
= json_real_value(json_object_get(parametersJSON,
"FirstStepSize"));
parameters->margin
= json_real_value(json_object_get(parametersJSON,
"Margin"));
parameters->invConditionNumber
= json_real_value(json_object_get(parametersJSON,
"InverseConditionNumber"));
parameters->slopeImprovementFactor
= json_real_value(json_object_get(parametersJSON,
"SlopeImprovementFactor"));
parameters->stepIncreaseFactor
= json_real_value(json_object_get(parametersJSON,
"StepIncreaseFactor"));
parameters->stepDecreaseFactor
= json_real_value(json_object_get(parametersJSON,
"StepDecreaseFactor"));
Solution * solution = NewSolution(experiment,
assignment,
space,
prior,
sigmaSquared,
parameters);
FreeAndClear(prior);
return solution;
}
Solution * NewSolutionFromFile(FILE * restrict f,
const Experiment * restrict experiment)
{
json_error_t jsonError;
json_t * restrict solutionJSON = json_loadf(f, &jsonError);
if (!solutionJSON) return NULL;
Solution * solution = NewSolutionFromJSON(solutionJSON, experiment);
json_decref(solutionJSON);
return solution;
}
Solution * NewSolutionFromFilename(const char * restrict filename,
const Experiment * restrict experiment)
{
json_error_t jsonError;
json_t * restrict solutionJSON = json_load_file(filename, &jsonError);
if (!solutionJSON) return NULL;
Solution * solution = NewSolutionFromJSON(solutionJSON, experiment);
json_decref(solutionJSON);
return solution;
}
static json_t * SolutionJSON(const Solution * restrict self)
{
json_t * restrict root = json_object();
const ClassAssignment * restrict assignment = NULL;
assignment = SolutionClassAssignment(self);
const Model * restrict model = ClassAssignmentModel(assignment);
const size_t classCount = ClassCount(model);
const SubjectSet * restrict subjectSet = NULL;
subjectSet = ClassAssignmentSubjectSet(assignment);
const size_t subjectCount = SubjectCount(subjectSet);
const double * restrict subjectClassDistributions = NULL;
subjectClassDistributions = SubjectClassDistributions(assignment);
json_t * restrict subjectClassDistributionsJSON = json_object();
for (size_t i = 0; i < subjectCount; i++) {
const double * distribution = NULL;
distribution = subjectClassDistributions + classCount * i;
json_t * restrict distributionJSON = NULL;
distributionJSON = json_array_with_vector(distribution,
classCount,
1);
const char * name = SubjectNameForIndex(subjectSet, i);
json_object_set_new(subjectClassDistributionsJSON,
name ? name : "",
distributionJSON);
}
json_object_set_new(root,
"PosteriorProbabilities",
subjectClassDistributionsJSON);
const ModelSpace * restrict space = SolutionModelSpace(self);
const size_t dimensionCount = DimensionCount(model);
const SpecificityType specificityType = ModelSpecificityType(model);
const StimulusSet * restrict stimulusSet = NULL;
stimulusSet = ModelSpaceStimulusSet(space);
const size_t stimulusCount = StimulusCount(stimulusSet);
if (classCount > 1 && (dimensionCount > 0 || specificityType)) {
const size_t weightsLength = ((specificityType
== GlobalSpecificities)
? SizeSum(dimensionCount, 1)
: dimensionCount);
const double * restrict weights = Weights(space);
json_t * restrict weightsJSON = json_array();
for (size_t t = 0; t < classCount; t++) {
const double * classWeights = weights + t;
json_t * restrict classWeightsJSON = NULL;
classWeightsJSON = json_array_with_vector(classWeights,
weightsLength,
classCount);
json_array_append_new(weightsJSON, classWeightsJSON);
}
json_object_set_new(root, "Weights", weightsJSON);
}
if (dimensionCount > 0) {
const double * restrict coordinates = Coordinates(space);
json_t * restrict coordinatesJSON = json_object();
for (size_t j = 0; j < stimulusCount; j++) {
const double * row = coordinates + dimensionCount * j;
json_t * restrict rowJSON = NULL;
rowJSON = json_array_with_vector(row,
dimensionCount,
1);
const char * name = NULL;
name = StimulusNameForIndex(stimulusSet, j);
json_object_set_new(coordinatesJSON,
name ? name : "", rowJSON);
}
json_object_set_new(root, "Coordinates", coordinatesJSON);
}
if (specificityType) {
const double * specificities = Specificities(space);
json_t * restrict specificitiesJSON = json_object();
for (size_t j = 0; j < stimulusCount; j++) {
json_t * restrict spJSON = NULL;
if (specificityType == ClassSpecificities) {
const double * col = specificities + j;
spJSON = json_array_with_vector(col,
classCount,
stimulusCount);
} else {
spJSON = json_null_or_real(specificities[j]);
}
const char * name = NULL;
name = StimulusNameForIndex(stimulusSet, j);
json_object_set_new(specificitiesJSON,
name ? name : "",
spJSON);
}
json_object_set_new(root,
"Specificities",
specificitiesJSON);
}
json_object_set_new(root,
"ParameterCount",
json_integer((int)AdjustedParameterCount(self)));
json_object_set_new(root,
"DegreesOfFreedom",
json_integer((int)DegreesOfFreedom(self)));
json_t * restrict distancesJSON = json_array();
for (size_t t = 0; t < classCount; t++) {
json_t * restrict classMeansJSON = json_array();
for (size_t k = 1; k < stimulusCount; k++) {
json_t * restrict rowJSON = json_array();
for (size_t j = 0; j < k; j++) {
const StimulusPair pair = { j, k };
const double d = DistanceForPairAndClass(space,
&pair,
t);
json_array_append_new(rowJSON,
json_null_or_real(d));
}
json_array_append_new(classMeansJSON, rowJSON);
}
json_array_append_new(distancesJSON, classMeansJSON);
}
json_object_set_new(root, "PredictedDissimilarities", distancesJSON);
const double * prior = PriorDistribution(self);
json_t * restrict priorJSON = json_array();
for (size_t t = 0; t < classCount; t++)
json_array_append_new(priorJSON, json_null_or_real(prior[t]));
json_object_set_new(root,
"PriorDistribution",
priorJSON);
json_object_set_new(root,
"EstimatedVariance",
json_null_or_real(EstimatedVariance(self)));
const Parameters * restrict parameters = SolutionParameters(self);
json_t * restrict parametersJSON = json_object();
json_object_set_new(parametersJSON,
"TorgersonStart",
(parameters->useTorgersonStart
? json_true()
: json_false()));
json_object_set_new(parametersJSON,
"KMeansStart",
(parameters->useKMeansStart
? json_true()
: json_false()));
json_object_set_new(parametersJSON,
"MaxEMIterationCount",
json_integer((int)parameters->maxEMIterationCount));
json_object_set_new(parametersJSON,
"EMImprovementAmount",
json_null_or_real(parameters->EMImprovementAmount));
json_object_set_new(parametersJSON,
"MaxMIterationCount",
json_integer((int)parameters->maxMIterationCount));
json_object_set_new(parametersJSON,
"MImprovementFactor",
json_null_or_real(parameters->MImprovementFactor));
json_object_set_new(parametersJSON,
"MaxSpatialIterationCount",
json_integer((int)parameters->maxSpatialIterationCount));
json_object_set_new(parametersJSON,
"MinSpecificityValue",
json_null_or_real(parameters->minSpecificityValue));
json_object_set_new(parametersJSON,
"SpatialImprovementFactor",
json_null_or_real(parameters->spatialImprovementFactor));
json_object_set_new(parametersJSON,
"MaxWeightIterationCount",
json_integer((int)parameters->maxWeightIterationCount));
json_object_set_new(parametersJSON,
"MinWeightValue",
json_null_or_real(parameters->minWeightValue));
json_object_set_new(parametersJSON,
"WeightImprovementFactor",
json_null_or_real(parameters->weightImprovementFactor));
json_object_set_new(parametersJSON,
"MaxSearchIterationCount",
json_integer((int)parameters->maxSearchIterationCount));
json_object_set_new(parametersJSON,
"FirstStepSize",
json_null_or_real(parameters->firstStepSize));
json_object_set_new(parametersJSON,
"Margin",
json_null_or_real(parameters->margin));
json_object_set_new(parametersJSON,
"InverseConditionNumber",
json_null_or_real(parameters->invConditionNumber));
json_object_set_new(parametersJSON,
"SlopeImprovementFactor",
json_null_or_real(parameters->slopeImprovementFactor));
json_object_set_new(parametersJSON,
"StepIncreaseFactor",
json_null_or_real(parameters->stepIncreaseFactor));
json_object_set_new(parametersJSON,
"StepDecreaseFactor",
json_null_or_real(parameters->stepDecreaseFactor));
json_object_set_new(root, "Parameters", parametersJSON);
json_object_set_new(root,
"LogLikelihood",
json_null_or_real(LogLikelihood(self)));
json_object_set_new(root,
"AkaikeCriterion",
json_null_or_real(AkaikeCriterion(self)));
json_object_set_new(root,
"AkaikeCriterionCorrected",
json_null_or_real(AkaikeCriterionCorrected(self)));
json_object_set_new(root,
"BayesianCriterion",
json_null_or_real(BayesianCriterion(self)));
return root;
}
void SaveSolutionToFile(const Solution * restrict self, FILE * restrict f)
{
json_t * restrict solutionJSON = SolutionJSON(self);
if (json_dumpf(solutionJSON, f, JSON_INDENT(8)|JSON_SORT_KEYS) != 0)
ExitWithError("Could not save file");
json_decref(solutionJSON);
}
void SaveSolutionToFilename(const Solution * restrict self,
const char * restrict filename)
{
json_t * restrict solutionJSON = SolutionJSON(self);
if (0
!= json_dump_file(solutionJSON,
filename,
JSON_INDENT(8)|JSON_SORT_KEYS))
ExitWithError("Could not save file");
json_decref(solutionJSON);
}