Пример #1
0
def setTpTw(data, realStepTime, tpValue, twValue, technique):
    """
    setTpTw is simple function to process RAW data form electrochemical
    analyzer. I can process data from SCV, DPV and NPV techniques.
    sig - signal with raw data (readout from A/D converter)
    realStepTime - total probing time of one step (i.e. in SCV it is tp, in DPV and
        NPV it is 2*tp
    tpValue - new tp time
    twValue - new wait time (tp + tw =< realStepTime)
    technique - type of technique: 'sc', 'scv', 'dp', 'dpv' 'dpasv', 'dpas' ,
        'np', 'npv', 'npasv', 'sqw', 'swv'

    if returns touple of 
    ( finalVector, onPulseVector, onStepVector)
    """
    #TODO: preallocate arrays ?
    sumtptw = twValue + tpValue
    assert (realStepTime >= sumtptw)
    averagedTmp = []
    scvLike = ['sc', 'scv']
    pulseLike = ['dp', 'dpv', 'np', 'npv']
    sqwLike = ['sqw', 'swv']
    for i in np.arange(0, len(data), realStepTime):
        st = (i + twValue)
        end = st + tpValue
        averagedTmp.append(np.mean(data[st:end]))

    if technique in scvLike:
        return averagedTmp, averagedTmp, averagedTmp

    elif technique in pulseLike:
        res = []
        partial1 = []
        partial2 = []
        for i in np.arange(0, len(averagedTmp) - 1, 2):
            i = int(i)
            res.append(averagedTmp[i + 1] - averagedTmp[i])
            partial1.append(averagedTmp[i])
            partial2.append(averagedTmp[i + 1])

        return res, partial1, partial2

    elif technique in sqwLike:
        res = []
        partial1 = []
        partial2 = []

        for i in np.arage(0, len(averagedTmp) - 1, 2):
            i = int(i)
            res.append(averagedTmp[i] - averagedTmp[i + 1])
            partial1.append(averagedTmp[i + 1])
            partial2.append(averagedTmp[i])
        return res, partial1, partial2

    else:
        raise LookupError('Unknown technique: %s' % technique)
Пример #2
0
 def backward(self, gradient=1):
     batch_size = self.y.shape[0]
     if self.y.size == self.y_hat.size:
         dx = (self.y_hat - self.y)/batch_size
     else:
         dx = self.y_hat.copy()
         dx[np.arage(batch_size), self.y]-=1
         dx = dx/batch_size
     
     return dx# -*- coding: utf-8 -*-
Пример #3
0
    def __init__(self, cMats, n_macro=2, nProc=1):

        check_matrices_shape(cMats)

        self.n_models = len(cMats)
        self.n_macro = 2
        self.n_micro = cMats[0].shape[0]

        self.uncombined = np.ones(self.n_micro, dtype=np.int32)
        self.stateskeep = np.arange(self.n_micro, dtype=np.int32)
        self.unmerged = np.ones(self.n_micro, dtype=np.int32)
        self.indices = np.arange(self.n_micro, dtype=np.int32)
        self.map = np.arage(self.n_micro, dtype=np.int32)
        self.pseud = np.ones(self.n_micro, dtype=np.float32) / self.n_micro
        self.nProc = nProc
Пример #4
0
    def create_bar(x,
                   title=None,
                   xlabel=None,
                   ylabel=None,
                   ticks='',
                   size=(6, 4),
                   axis='v'):
        '''Create a bar chart using matplotlib and the passed arguments
        x - List: Series data to be plotted
        Title, xlabel, ylabel - Str: Text for the figure title and axes. Axes are reversed for horionztal charts
        Size - Tuple: Two element tuple defining the width and height of the figure
        Axis - Str: h for horizontal bar charts, y for vertical. Default = vertical
        Code for adding bar labels taken from stack overflow
        https://stackoverflow.com/questions/30228069/how-to-display-the-value-of-the-bar-on-each-bar-with-pyplot-barh'''

        mpl.style.use('ggplot')

        plt.figure(figsize=size)
        if axis == 'h':
            plt.barh(np.arange(1, len(x) + 1), x, tick_label=ticks)
            plt.xlabel(ylabel, fontsize=10)
            plt.ylabel(xlabel, fontsize=10)

            for i, v in enumerate(x):
                plt.text(v + 0.02,
                         i + .9,
                         str(v),
                         color='blue',
                         fontweight='bold')
        else:
            plt.bar(np.arage(1, len(x) + 1), x, tick_label=ticks)
            plt.xlabel(xlabel, fontsize=10)
            plt.ylabel(ylabel, fontsize=10)

        plt.title(title, fontsize=14)
        plt.xticks(fontsize=8)
        plt.yticks(fontsize=8)

        plt.show()
Пример #5
0
kpca = KernelPCA(n_components = 2, kernel = 'rbf')
X_train = kpca.fit_transform(X_train)
X_test = kpca.transform(X_test)

#Fitting Logistic regression to the Training set
from sklearn.linear_model import LogisticRegression
classifier = LogisticRegression(random_state = 0)
classifer.fit(X_train, y_train)

#Predicting the Test set results
y_pred = classifier.predict(X_test)

#Making the Confusion Matrix
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)

#Visualizing the Training set results (use this to see test set results by changing the variable)
from matplotlib.colors import ListedColormap
X_set, y_set = X_train, y_train
X1, X2 = np.meshgrind(np.arage(start = X_set[:, 0].min() - 1, stop = X_set[:, 0].max() + 1, step = 0.01), np.arange(start = X_set[:, 1].min() - 1, stop = X_set[:, 1].max() + 1, step 0.01))
plt.contourf(X1, X2, classifier.predict(np.array([X1.ravel(), X2.ravel()]).T).reshape(X1.shape), alpha = 0.75, cmap = ListedColormap(('red', 'green')))
plt.xlim(X1.min(), X1.max())
plt.ylim(X2.min(), X2.max())
for i, j in enumerate(np.unique(y_set)):
	plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1], 
		c = ListedColormap(('red', 'green'))(i), label = j)
plt.title('Logistic Regression (Training set)')
plt.xlabel('Age')
plt.ylabel('Estimated Salary')
plt.legend()
plt.show()
Пример #6
0
import numpy as np
import matplotlib.pylab as plt


def sigmoid(x):  # 시그모이드 함수
    return 1 / (1 + np.exp(-x))


def relu(x):  # 렐루라고 부름. p.76 ReLU
    return np.maximum(0, x)


x = np.array([-1.0, 1.0, 2.0])
print(sigmoid(x))

t = np.array([1.0, 2.0, 3.0])
print(1.0 + t)
print(1.0 / t)

x = np.arage(-5.0, 5.0, 0.1)
y = sigmoid(x)
plt.plot(x, y)
plt.ylim(-0.1, 1.1)  # y축 범위 지정
#plt.show()
# 정교한 값이 필요하여 계단함수보다 시그모이드 함수를 좀 더 많이 사용함(현재)
Пример #7
0
print v


# In[4]:

2*v


# In[5]:

import numpy as np


# In[6]:

v=np.arage(1,6)


# In[7]:

v=np.arange(1,6)


# In[8]:

v


# In[9]:

2*v
Пример #8
0
 def _get_edge(self):
     if self.dataset == 'kinetics':
         num_node = 18
         neighbor_link = [(4, 3), (3, 2), (7, 6), (6, 5),
                          (13, 12), (12, 11), (10, 9), (9, 8), (11, 5),
                          (8, 2), (5, 1), (2, 1), (0, 1), (15, 0), (14, 0),
                          (17, 15), (16, 14), (8, 11)]
         connect_joint = np.array(
             [1, 1, 1, 2, 3, 1, 5, 6, 2, 8, 9, 5, 11, 12, 0, 0, 14, 15])
         parts = [
             np.array([5, 6, 7]),  # left_arm
             np.array([2, 3, 4]),  # right_arm
             np.array([11, 12, 13]),  # left_leg
             np.array([8, 9, 10]),  # right_leg
             np.array([0, 1, 14, 15, 16, 17])  # torso
         ]
     elif self.dataset == 'ntu':
         num_node = 25
         neighbor_1base = [(1, 2), (2, 21), (3, 21),
                           (4, 3), (5, 21), (6, 5), (7, 6), (8, 7), (9, 21),
                           (10, 9), (11, 10), (12, 11), (13, 1), (14, 13),
                           (15, 14), (16, 15), (17, 1), (18, 17), (19, 18),
                           (20, 19), (22, 23), (23, 8), (24, 25), (25, 12)]
         neighbor_link = [(i - 1, j - 1) for (i, j) in neighbor_1base]
         connect_joint = np.array([
             2, 2, 21, 3, 21, 5, 6, 7, 21, 9, 10, 11, 1, 13, 14, 15, 1, 17,
             18, 19, 2, 23, 8, 25, 12
         ]) - 1
         parts = [
             np.array([5, 6, 7, 8, 22, 23]) - 1,  # left_arm
             np.array([9, 10, 11, 12, 24, 25]) - 1,  # right_arm
             np.array([13, 14, 15, 16]) - 1,  # left_leg
             np.array([17, 18, 19, 20]) - 1,  # right_leg
             np.array([1, 2, 3, 4, 21]) - 1  # torso
         ]
     elif self.dataset == 'ntu_ax':
         num_node = 118
         neighbor_1base = [
             (1, 2),
             (3, 2),
             (4, 3),
             (5, 4),
             (6, 2),
             (7, 6),
             (8, 7),
             (9, 2),
             (10, 9),
             (11, 10),
             (12, 11),
             (13, 9),
             (14, 13),
             (15, 14),
             (16, 1),
             (17, 1),
             (18, 16),
             (19, 17),
             (20, 15),
             (21, 20),
             (22, 15),
             (23, 12),
             (24, 23),
             (25, 12),
             (26, 5),
             (27, 26),
             (28, 27),
             (29, 28),
             (30, 29),
             (31, 26),  # Left hand coordinates
             (32, 31),
             (33, 32),
             (34, 33),
             (35, 26),
             (36, 35),
             (37, 36),
             (38, 37),
             (39, 26),
             (40, 39),
             (41, 40),
             (42, 41),
             (43, 26),
             (44, 43),
             (45, 44),
             (46, 45),
             (47, 8),
             (48, 47),
             (49, 48),  # Right hand coordinates
             (50, 49),
             (51, 50),
             (52, 47),
             (53, 52),
             (54, 53),
             (55, 54),
             (56, 47),
             (57, 56),
             (58, 57),
             (59, 58),
             (60, 47),
             (61, 60),
             (62, 61),
             (63, 62),
             (64, 47),
             (65, 64),
             (66, 65),
             (67, 66),
             (68, 69),
             (69, 70),
             (70, 71),
             (71, 72),
             (73, 74),
             (74, 75),  # Face coordinates
             (75, 76),
             (76, 77),
             (78, 1),
             (79, 78),
             (80, 79),
             (81, 80),
             (82, 83),
             (83, 84),
             (84, 85),
             (85, 86),
             (87, 16),
             (88, 87),
             (89, 88),
             (90, 89),
             (91, 90),
             (92, 91),
             (92, 87),
             (93, 17),
             (94, 93),
             (95, 94),
             (96, 95),
             (97, 96),
             (98, 97),
             (98, 93),
             (99, 100),
             (100, 101),
             (101, 102),
             (102, 103),
             (103, 104),
             (104, 105),
             (105, 106),
             (106, 107),
             (107, 108),
             (108, 109),
             (109, 110),
             (110, 99),
             (111, 112),
             (112, 113),
             (113, 114),
             (114, 115),
             (115, 116),
             (116, 117),
             (117, 118),
             (118, 111)
         ]
         neighbor_link = [(i - 1, j - 1) for (i, j) in neighbor_1base]
         connect_joint = np.array([
             2, 2, 21, 3, 21, 5, 6, 7, 21, 9, 10, 11, 1, 13, 14, 15, 1, 17,
             18, 19, 2, 23, 8, 25, 12
         ]) - 1
         parts = [
             np.array([5, 6, 7]),  # left_arm
             np.array([2, 3, 4]),  # right_arm
             np.array([12, 13, 14, 19, 20, 21]),  # left_leg
             np.array([9, 10, 11, 22, 23, 24]),  # right_leg
             np.array([1, 8]),  # torso
             np.array([0, 15, 16, 17, 18]),  # head
             np.arange(21) + 25,  # left fingers
             np.arange(21) + 46,  # right fingers
             np.arage(51) + 67  # face
         ]
     elif self.dataset == 'ntu_hx':
         num_node = 67
         neighbor_1base = [
             (1, 2),
             (3, 2),
             (4, 3),
             (5, 4),
             (6, 2),
             (7, 6),
             (8, 7),
             (9, 2),
             (10, 9),
             (11, 10),
             (12, 11),
             (13, 9),
             (14, 13),
             (15, 14),
             (16, 1),
             (17, 1),
             (18, 16),
             (19, 17),
             (20, 15),
             (21, 20),
             (22, 15),
             (23, 12),
             (24, 23),
             (25, 12),
             (26, 5),
             (27, 26),
             (28, 27),
             (29, 28),
             (30, 29),
             (31, 26),  # Left hand coordinates
             (32, 31),
             (33, 32),
             (34, 33),
             (35, 26),
             (36, 35),
             (37, 36),
             (38, 37),
             (39, 26),
             (40, 39),
             (41, 40),
             (42, 41),
             (43, 26),
             (44, 43),
             (45, 44),
             (46, 45),
             (47, 8),
             (48, 47),
             (49, 48),  # Right hand coordinates
             (50, 49),
             (51, 50),
             (52, 47),
             (53, 52),
             (54, 53),
             (55, 54),
             (56, 47),
             (57, 56),
             (58, 57),
             (59, 58),
             (60, 47),
             (61, 60),
             (62, 61),
             (63, 62),
             (64, 47),
             (65, 64),
             (66, 65),
             (67, 66)
         ]
         neighbor_link = [(i - 1, j - 1) for (i, j) in neighbor_1base]
         connect_joint = np.array([
             2, 2, 21, 3, 21, 5, 6, 7, 21, 9, 10, 11, 1, 13, 14, 15, 1, 17,
             18, 19, 2, 23, 8, 25, 12
         ]) - 1
         parts = [
             np.array([5, 6, 7]),  # left_arm
             np.array([2, 3, 4]),  # right_arm
             np.array([12, 13, 14, 19, 20, 21]),  # left_leg
             np.array([9, 10, 11, 22, 23, 24]),  # right_leg
             np.array([1, 8]),  # torso
             np.array([0, 15, 16, 17, 18]),  # head
             np.arange(21) + 25,  # left fingers
             np.arange(21) + 46,  # right fingers
         ]
     elif self.dataset == 'sysu':
         num_node = 20
         neighbor_1base = [(1, 2), (2, 3), (3, 4), (3, 5), (5, 6), (6, 7),
                           (7, 8), (3, 9), (9, 10), (10, 11), (11, 12),
                           (1, 13), (13, 14), (14, 15), (15, 16), (1, 17),
                           (17, 18), (18, 19), (19, 20)]
         neighbor_link = [(i - 1, j - 1) for (i, j) in neighbor_1base]
         connect_joint = np.array([
             2, 2, 2, 3, 3, 5, 6, 7, 3, 9, 10, 11, 1, 13, 14, 15, 1, 17, 18,
             19
         ]) - 1
         parts = [
             np.array([5, 6, 7, 8]) - 1,  # left_arm
             np.array([9, 10, 11, 12]) - 1,  # right_arm
             np.array([13, 14, 15, 16]) - 1,  # left_leg
             np.array([17, 18, 19, 20]) - 1,  # right_leg
             np.array([1, 2, 3, 4]) - 1  # torso
         ]
     elif self.dataset == 'ucla':
         num_node = 20
         neighbor_1base = [(1, 2), (2, 3), (3, 4), (3, 5), (5, 6), (6, 7),
                           (7, 8), (3, 9), (9, 10), (10, 11), (11, 12),
                           (1, 13), (13, 14), (14, 15), (15, 16), (1, 17),
                           (17, 18), (18, 19), (19, 20)]
         neighbor_link = [(i - 1, j - 1) for (i, j) in neighbor_1base]
         connect_joint = np.array([
             2, 2, 2, 3, 3, 5, 6, 7, 3, 9, 10, 11, 1, 13, 14, 15, 1, 17, 18,
             19
         ]) - 1
         parts = [
             np.array([5, 6, 7, 8]) - 1,  # left_arm
             np.array([9, 10, 11, 12]) - 1,  # right_arm
             np.array([13, 14, 15, 16]) - 1,  # left_leg
             np.array([17, 18, 19, 20]) - 1,  # right_leg
             np.array([1, 2, 3, 4]) - 1  # torso
         ]
     elif self.dataset == 'cmu':
         num_node = 26
         neighbor_1base = [(1, 2), (2, 3), (3, 4), (5, 6), (6, 7), (7, 8),
                           (1, 9), (5, 9), (9, 10), (10, 11), (11, 12),
                           (12, 13), (13, 14), (12, 15), (15, 16), (16, 17),
                           (17, 18), (18, 19), (17, 20), (12, 21), (21, 22),
                           (22, 23), (23, 24), (24, 25), (23, 26)]
         neighbor_link = [(i - 1, j - 1) for (i, j) in neighbor_1base]
         connect_joint = np.array([
             9, 1, 2, 3, 9, 5, 6, 7, 10, 10, 10, 11, 12, 13, 12, 15, 16, 17,
             18, 17, 12, 21, 22, 23, 24, 23
         ]) - 1
         parts = [
             np.array([15, 16, 17, 18, 19, 20]) - 1,  # left_arm
             np.array([21, 22, 23, 24, 25, 26]) - 1,  # right_arm
             np.array([1, 2, 3, 4]) - 1,  # left_leg
             np.array([5, 6, 7, 8]) - 1,  # right_leg
             np.array([9, 10, 11, 12, 13, 14]) - 1  # torso
         ]
     elif self.dataset == 'h36m':
         num_node = 20
         neighbor_1base = [(1, 2), (2, 3), (3, 4), (5, 6), (6, 7), (7, 8),
                           (1, 9), (5, 9), (9, 10), (10, 11), (11, 12),
                           (10, 13), (13, 14), (14, 15), (15, 16), (10, 17),
                           (17, 18), (18, 19), (19, 20)]
         neighbor_link = [(i - 1, j - 1) for (i, j) in neighbor_1base]
         connect_joint = np.array([
             9, 1, 2, 3, 9, 5, 6, 7, 9, 9, 10, 11, 10, 13, 14, 15, 10, 17,
             18, 19
         ]) - 1
         parts = [
             np.array([13, 14, 15, 16]) - 1,  # left_arm
             np.array([17, 18, 19, 20]) - 1,  # right_arm
             np.array([1, 2, 3, 4]) - 1,  # left_leg
             np.array([5, 6, 7, 8]) - 1,  # right_leg
             np.array([9, 10, 11, 12]) - 1  # torso
         ]
     else:
         num_node, neighbor_link, connect_joint, parts = 0, [], [], []
         logging.info('')
         logging.error('Error: Do NOT exist this dataset: {}!'.format(
             self.dataset))
         raise ValueError()
     self_link = [(i, i) for i in range(num_node)]
     edge = self_link + neighbor_link
     return num_node, edge, connect_joint, parts
Пример #9
0
# Example1
# import numpy as np
# a = np.arange(20)
# s = slice(2, 20, 2)
# print(a[s])

# Example2
import numpy as np
a = np.arage(10)
b = a[2:7:2]
print(b)