MCPcopy Create free account
hub / github.com/creatale/node-dv / ReadPrototype

Function ReadPrototype

deps/tesseract/classify/clusttool.cpp:114–231  ·  view source on GitHub ↗

* This routine reads a textual description of a prototype from * the specified file. * * Exceptions: * - ILLEGALSIGNIFICANCESPEC * - ILLEGALSAMPLECOUNT * - ILLEGALMEANSPEC * - ILLEGALVARIANCESPEC * - ILLEGALDISTRIBUTION * @param File open text file to read prototype from * @param N number of dimensions used in prototype * @return List of prototypes * @note Globals: None * @note Histor

Source from the content-addressed store, hash-verified

112 * @note History: 6/6/89, DSJ, Created.
113 */
114PROTOTYPE *ReadPrototype(FILE *File, uinT16 N) {
115 char Token[TOKENSIZE];
116 int Status;
117 PROTOTYPE *Proto;
118 int SampleCount;
119 int i;
120
121 if ((Status = tfscanf(File, "%s", Token)) == 1) {
122 Proto = (PROTOTYPE *) Emalloc (sizeof (PROTOTYPE));
123 Proto->Cluster = NULL;
124 if (Token[0] == 's')
125 Proto->Significant = TRUE;
126 else
127 Proto->Significant = FALSE;
128
129 Proto->Style = ReadProtoStyle (File);
130
131 if ((tfscanf(File, "%d", &SampleCount) != 1) || (SampleCount < 0))
132 DoError (ILLEGALSAMPLECOUNT, "Illegal sample count");
133 Proto->NumSamples = SampleCount;
134
135 Proto->Mean = ReadNFloats (File, N, NULL);
136 if (Proto->Mean == NULL)
137 DoError (ILLEGALMEANSPEC, "Illegal prototype mean");
138
139 switch (Proto->Style) {
140 case spherical:
141 if (ReadNFloats (File, 1, &(Proto->Variance.Spherical)) == NULL)
142 DoError (ILLEGALVARIANCESPEC, "Illegal prototype variance");
143 Proto->Magnitude.Spherical =
144 1.0 / sqrt ((double) (2.0 * PI * Proto->Variance.Spherical));
145 Proto->TotalMagnitude =
146 pow (Proto->Magnitude.Spherical, (float) N);
147 Proto->LogMagnitude = log ((double) Proto->TotalMagnitude);
148 Proto->Weight.Spherical = 1.0 / Proto->Variance.Spherical;
149 Proto->Distrib = NULL;
150 break;
151 case elliptical:
152 Proto->Variance.Elliptical = ReadNFloats (File, N, NULL);
153 if (Proto->Variance.Elliptical == NULL)
154 DoError (ILLEGALVARIANCESPEC, "Illegal prototype variance");
155 Proto->Magnitude.Elliptical =
156 (FLOAT32 *) Emalloc (N * sizeof (FLOAT32));
157 Proto->Weight.Elliptical =
158 (FLOAT32 *) Emalloc (N * sizeof (FLOAT32));
159 Proto->TotalMagnitude = 1.0;
160 for (i = 0; i < N; i++) {
161 Proto->Magnitude.Elliptical[i] =
162 1.0 /
163 sqrt ((double) (2.0 * PI * Proto->Variance.Elliptical[i]));
164 Proto->Weight.Elliptical[i] =
165 1.0 / Proto->Variance.Elliptical[i];
166 Proto->TotalMagnitude *= Proto->Magnitude.Elliptical[i];
167 }
168 Proto->LogMagnitude = log ((double) Proto->TotalMagnitude);
169 Proto->Distrib = NULL;
170 break;
171 case mixed:

Callers 1

ReadNormProtosMethod · 0.85

Calls 8

tfscanfFunction · 0.85
EmallocFunction · 0.85
ReadProtoStyleFunction · 0.85
DoErrorFunction · 0.85
ReadNFloatsFunction · 0.85
sqrtFunction · 0.85
powFunction · 0.85
logFunction · 0.85

Tested by

no test coverage detected