File: t_MixtureClassifier_std.py

package info (click to toggle)
openturns 1.24-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 66,204 kB
  • sloc: cpp: 256,662; python: 63,381; ansic: 4,414; javascript: 406; sh: 180; xml: 164; yacc: 123; makefile: 98; lex: 55
file content (37 lines) | stat: -rwxr-xr-x 1,260 bytes parent folder | download | duplicates (2)
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
#! /usr/bin/env python

import openturns as ot

ot.TESTPREAMBLE()
ot.RandomGenerator.SetSeed(0)

# Create a collection of distribution
aCollection = [ot.Normal(0.0, 4), ot.Uniform(5.0, 7.0), ot.Triangular(7.0, 8.0, 9.0)]

# Instantiate one distribution object
distribution = ot.Mixture(aCollection)
print("mixture=", distribution)
classifier = ot.MixtureClassifier(distribution)
inS = ot.Sample([[2.0], [4.0], [6.0], [8.0]])

for i in range(inS.getSize()):
    print("inP=", inS[i], " class=", classifier.classify(inS[i]))

print("classes=", classifier.classify(inS))

for i in range(inS.getSize()):
    for j in range(len(aCollection)):
        grade = classifier.grade(inS[i], j)
        # TODO JM: remove the check after the use of infs has been thoroughly tested
        if grade <= ot.SpecFunc.LowestScalar:
            grade *= 2.0
        print("inP=", inS[i], " grade|", j, "= %g" % grade)

for j in range(len(aCollection)):
    grades = classifier.grade(inS, ot.Indices(inS.getSize(), j))
    for num, grade in enumerate(grades):
        # TODO JM: remove the check after the use of infs has been thoroughly tested
        if grade <= ot.SpecFunc.LowestScalar:
            grade *= 2.0
        grades[num] = grade
    print("grades|", j, "=", grades)