Пример #1
0
 def _preProcessingData(self, x, y):
     for i in range(len(y.data)):
         for k in range(len(x.data[0])):
             if (type(x.data[i][k]) is not Rdm):
                 x.data[i][k] = Rdmia.number(x.data[i][k])
         if (type(y.data[i]) is not Rdm):
             y.data[i][0] = Rdmia.number(y.data[i][0])
Пример #2
0
def rosenbrock(x):  # rosen.m
    """ http://en.wikipedia.org/wiki/Rosenbrock_function """
    # a sum of squares, so LevMar (scipy.optimize.leastsq) is pretty good
    x = np.asarray_chkfinite(x)
    x0 = x[:-1]
    x1 = x[1:]
    return (sum((1.0 - x0)**2.0) + rdmia.number(100.0) * sum(
        (x1 - x0**2.0)**2.0))
Пример #3
0
def makeList(steps, dim):
    result = []
    r = []
    for k in steps:
        for i in range(dim):
            r.append(rdmia.number(k))
        result.append(r)
        r = []

    return result
Пример #4
0
    def predict(self, x):
        r_list = []
        if (self._isMult):
            for val in range(len(x)):
                resultLow = sum([
                    self._predictorsLow.data[i] * x[val][i].lower()
                    for i in range(len(self._predictorsLow.data))
                ])
                resultUp = sum([
                    self._predictorsUp.data[i] * x[val][i].upper()
                    for i in range(len(self._predictorsUp.data))
                ])
                r_list.append(Rdmia.number(resultLow, resultUp))
        else:
            for val in range(len(x)):
                result = sum([
                    self._predictors.data[i] * x[val][i]
                    for i in range(len(self._predictors.data))
                ])
                r_list.append(result)
                #r = qm.midpoint(self._predictors.data[0] + self._predictors.data[1]*x.data[val][1])

        return r_list
Пример #5
0
    def fit(self, x_data, y_data, kernel='std', alpha=0.1):
        #x_1 = (inv_by_adjugate(midPointMatrix(x.T.dot(x))))
        #self._preProcessingData(x,y)

        #First part of method minimum square
        if (kernel == 'std'):
            x = Rdmia.array(x_data)
            y = Rdmia.array(y_data)

            x_1 = x.T.dot(x).midPointMatrix

            x_1 = x_1.I

            #y_2 = midPointMatrix(x.T.dot(y))
            y_2 = x.T.dot(y).midPointMatrix

            #Calculated predictors beta
            z = (x_1).dot(y_2)

            self._predictors = Rdmia.array(
                [z.data[i][0] for i in range(len(z.data))])
        elif (kernel == 'multidimensional'):
            self._isMult = True

            opt_minium = 0.0
            opt_maximum = 0.0
            for i in np.arange(0.0, 1.0, alpha):
                x = Rdmia.arrayAlpha(x_data, i)
                y_min, y_max = Rdmia.arrayMinMax(y_data)

                x_1 = x.T.dot(x)

                x_1 = x_1.I

                #y_2 = midPointMatrix(x.T.dot(y))
                y_2_min = x.T.dot(y_min)
                y_2_max = x.T.dot(y_max)

                #Calculated predictors beta
                z_min = (x_1).dot(y_2_min)
                z_max = (x_1).dot(y_2_max)

                #print(z.data)

                #self._predictorsLow = (Rdmia.array([z_min.data[i][0] for i in range(len(z_min.data))]))
                #self._predictorsUp = (Rdmia.array([z_max.data[i][0] for i in range(len(z_max.data))]))

                opt_min, opt_max = self._optimizations(x_data, (Rdmia.array(
                    [z_min.data[i][0]
                     for i in range(len(z_min.data))])), (Rdmia.array(
                         [z_max.data[i][0] for i in range(len(z_max.data))])),
                                                       y_min, y_max)

                if (i == 0):
                    self._predictorsLow = (Rdmia.array(
                        [z_min.data[i][0] for i in range(len(z_min.data))]))
                    self._predictorsUp = (Rdmia.array(
                        [z_max.data[i][0] for i in range(len(z_max.data))]))
                    opt_minimum = opt_min
                    opt_maximum = opt_max
                elif (opt_min < opt_minium):
                    self._predictorsLow = (Rdmia.array(
                        [z_min.data[i][0] for i in range(len(z_min.data))]))
                    opt_minimum = opt_min
                elif (opt_max < opt_maximum):
                    self._predictorsUp = (Rdmia.array(
                        [z_max.data[i][0] for i in range(len(z_max.data))]))
                    opt_maximum = opt_max

        #Calculte Status
        y_pred = self.predict(x_data)
        self._coefDetermination = self._coefDetermination(y_data, y_pred)
        self._rmse = self._RMSE(y_data, y_pred)
        print("### STATISTICS OF MODEL ###")
        print("# RMSE: ", self._rmse)
        print("# Coefficiente of Determination: ", self._coefDetermination)
        print("#")
Пример #6
0
    def _mean(self, d):
        mean = Rdmia.number(0.0)
        for val in d:
            mean += val[0]

        return mean / len(d)
Пример #7
0
    def _RMSE(self, y, y_pred):
        lower = 0.0
        upper = 0.0
        tot = 0.0
        for val in range(len(y)):
            lower += (y[val][0].lower() - y_pred[val].lower())
            upper += (y[val][0].upper() - y_pred[val].upper())

        lower = (lower**2.0 / len(y))**(1.0 / 2.0)
        upper = (upper**2.0 / len(y))**(1.0 / 2.0)
        return lower, upper


if __name__ == "__main__":

    Rdmia.setDotPrecision(2)
    '''
	x = Rdmia.array([[Rdmia.number(1),Rdmia.number(90,100)],
	[Rdmia.number(1),Rdmia.number(90,130)],
	[Rdmia.number(1),Rdmia.number(140,180)],
	[Rdmia.number(1),Rdmia.number(110,142)],
	[Rdmia.number(1),Rdmia.number(90,100)],
	[Rdmia.number(1),Rdmia.number(130,160)],
	[Rdmia.number(1),Rdmia.number(60,100)],
	[Rdmia.number(1),Rdmia.number(130,160)],
	[Rdmia.number(1),Rdmia.number(110,190)],
	[Rdmia.number(1),Rdmia.number(138,180)],
	[Rdmia.number(1),Rdmia.number(110,150)]])


	x = [[Rdmia.number(1),Rdmia.number(90,100)],
Пример #8
0
        r = []

    return result


#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
if __name__ == "__main__":  # standalone test --
    import sys
    import json

    dims = [2, 3]  #dimensions
    nstep = 50  #iterations
    seed = 1
    init = 1
    rdmia.setDotPrecision(0.1)
    print("PRECISION: ", rdmia.precision())

    problems = {}
    # to change these params in sh or ipython, run this.py  a=1  b=None  c=[3] ...
    for arg in sys.argv[1:]:
        exec(arg)

    np.set_printoptions(
        threshold=20,
        edgeitems=5,
        linewidth=120,
        suppress=True,
        formatter=dict(float=lambda x: "%.2g" % x))  # float arrays %.2g
    np.random.seed(seed)