/
datacomplex.py
141 lines (125 loc) · 4.11 KB
/
datacomplex.py
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
from __future__ import division
import numpy as np
import time
import sys
import random
from termcolor import *
from function import *
from matplotlib import pyplot as plt
import matplotlib.lines as mlines
import math
import copy
from termcolor import colored
from parameters import *
class DataComplex:
data = np.empty((0,INPUT_DIM))
outputs = np.empty((0,OUTPUT_DIM))
def __init__(self, iData,iOut):
self.data = iData
self.outputs = iOut
def newData(self,newPoint):
self.data = np.append(self.data,[newPoint],axis=0)
def newOut(self,newPoint):
self.outputs = np.append(self.outputs,[newPoint],axis=0)
def loadData(add):
xad = add + 'xData.txt'
yad = add + 'yData.txt'
xData = np.loadtxt(xad, dtype=float)
xData = xData.reshape(len(xData),1)
yData = np.loadtxt(yad, dtype=float)
return xData,yData
def CreatePath(str_):
path = os.getcwd()
print ("The current working directory is %s" % path)
path = str_
try:
os.mkdir(path)
except OSError:
print ("Creation of the directory %s failed" % path)
else:
print ("Successfully created the directory %s " % path)
print("_____________________________")
def print_dots(string):
sys.stdout.write(string)
sys.stdout.flush()
def print_fancy(string,val):
print_dots(string)
time.sleep(val)
print_dots('.')
time.sleep(val)
print_dots('.')
time.sleep(val)
print_dots('.')
time.sleep(val)
time.sleep(val)
print_dots('.')
time.sleep(val)
print()
######################################## DEF I, works good, decided to be revised tho
def createPoints_(deepness,breadth):
points_ = {}
for i in range(1,deepness+1):
#temp_x = np.arange(0,i/3,i/(breadth*3))
#temp_x = np.arange(0,i,i/(breadth))
temp_x = np.linspace(0, i/ANGLE, num=breadth)
temp_y = np.zeros(temp_x.shape)+i
temp_merge = np.vstack((temp_x,temp_y))
points_[i] = temp_merge
for key in points_:
if key!=1:
points_[1] = np.hstack((points_[1],points_[key]))
return points_[1].T
######################################## DEF II, works good, decided to be revised tho
def createPoints(deepness,breadth):
points_ = {}
for i in range(1,deepness+1):
#temp_x = np.arange(0,i/3,i/(breadth*3))
#temp_x = np.arange(0,i,i/(breadth))
temp_x = np.linspace(0, -i/ANGLE, num=breadth)
temp_y = np.zeros(temp_x.shape)+i
temp_merge = np.vstack((temp_x,temp_y))
points_[i] = temp_merge
for key in points_:
if key!=1:
points_[1] = np.hstack((points_[1],points_[key]))
points_2 = {}
for i in range(1,-deepness-1,-1):
#temp_x = np.arange(0,i/3,i/(breadth*3))
#temp_x = np.arange(0,i,i/(breadth))
temp_x = np.linspace(0, -i/ANGLE, num=breadth)
temp_y = np.zeros(temp_x.shape)+i
temp_merge = np.vstack((temp_x,temp_y))
points_2[i] = temp_merge
for key in points_2:
if key!=1:
points_[1] = np.hstack((points_[1],points_2[key]))
return points_[1].T
def info(*arg):
for i in range(len(arg)):
cprint("Shape of "+str(i)+" is "+str(arg[i].shape),"green")
def initvals_(bounds,INITIAL,flag_):
str_ = "Initializing " + str(INITIAL) + " Data"
print_fancy(str_,0.1)
gData = np.zeros([INITIAL,INPUT_DIM])
for i in range(0,INITIAL):
for j in range(0,INPUT_DIM):
gData[i,j] = random.uniform(bounds['min'][j], bounds['max'][j])
gDataB = copy.deepcopy(gData)
if flag_:
gDataY = function(gDataB)
return gData,gDataY
else:
return gData.T
def initvals_no_balls(bounds,INITIAL,flag_):
str_ = "Initializing " + str(INITIAL) + " Data"
print_fancy(str_,0.1)
gData = np.zeros([INITIAL,INPUT_DIM])
for i in range(0,INITIAL):
for j in range(0,INPUT_DIM):
gData[i,j] = random.uniform(bounds['min'][j], bounds['max'][j]/100)
gDataB = copy.deepcopy(gData)
if flag_:
gDataY = function(gDataB)
return gData,gDataY
else:
return gData.T