root/lang/python/tremolo/indications/normalized.py @ 32149

Revision 32149, 2.6 kB (checked in by rezoo, 4 years ago)

indications/volatility add Skew,Kurtosis,and Moment

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2#-*- coding:utf-8 -*-
3
4import sys
5from foundation import Indication
6from numpy import int32
7
8class Normalized (Indication):
9        """
10        対象の指標を0から1の範囲で正規化するクラスです.
11        """
12        @classmethod
13        def isRealIndication(cls): return True
14        @classmethod
15        def getType(cls): return float
16       
17        def __init__(self, indication, start, end, parent=None):
18                """
19                オブジェクトのコンストラクタです.
20               
21                indication : 対象となる指標.このオブジェクトは
22                             Indicationのサブクラスのオブジェクトでなければなりません.
23                start      : サンプルに用いるtの開始範囲
24                end        : サンプルに用いるtの終了範囲
25                parent     : 親となるオブジェクト
26                """
27                Indication.__init__(self, parent=parent)
28                self.setIndication(indication)
29                if (type(start) == int or type(start) == int32):
30                        self.__s = start
31                else: raise TypeError("the variable 'start' is not valid.")
32                if (type(end) == int or type(start) == int32):
33                        self.__e = end
34                else: raise TypeError("the variable 'end' is not valid.")
35                self.__initRange()
36       
37        def getStart(self): return self.__s
38        def setStart(self, s):
39                if (type(s) == int or type(s) == int32) and s < self.__e:
40                        self.__s = s
41                        self.__initRange()
42                else: raise TypeError("the variable 'start' is not valid.")
43        start = property(getStart, setStart)
44       
45        def getEnd(self): return self.__e
46        def setEnd(self, e):
47                if (type(e) == int or type(e) == int32) and self.__s < e:
48                        self.__e = e
49                        self.__initRange()
50                else: raise TypeError("the variable 'end' is not valid.")
51        end = property(getEnd, setEnd)
52       
53        def __initRange(self):
54                dat = [self.indication.evaluate(t) for t in xrange(self.__s, self.__e)]
55                self.__M     = max(dat)
56                self.__m     = min(dat)
57                self.__range = self.__M - self.__m
58       
59        def getIndication(self): return self.__indication
60        def setIndication(self, i):
61                if issubclass(i.__class__, Indication):
62                        self.__indication = i
63                else: raise TypeError
64        indication = property(getIndication, setIndication)
65       
66        def getDescription(self):
67                return "%s(normalized)" % self.indication.getDescription()
68       
69        def getMax(self): return self.__M
70        def setMax(self, M):
71                if type(M) == int or type(M) == int32: self.__M = M
72        max = property(getMax, setMax)
73       
74        def getMin(self): return self.__m
75        def setMin(self, m):
76                if type(m) == int or type(m) == int32: self.__m = m
77        min = property(getMin, setMin)
78       
79        def evaluate(self, t):
80                return (self.indication.evaluate(t)-self.__m)/float(self.__range)
81       
82        def reverse(self, x):
83                """このオブジェクトによって写像された空間から、本来の空間へと戻します."""
84                return (x*self.__range) + self.__m
Note: See TracBrowser for help on using the browser.