File size: 1,824 Bytes
8c348c5
29cce3f
8c348c5
29cce3f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38e3b7b
 
14841f9
 
 
 
8c348c5
 
29cce3f
8c348c5
 
 
14841f9
 
 
 
 
8c348c5
 
 
 
 
 
 
 
29cce3f
38e3b7b
 
 
 
 
 
 
 
 
 
 
 
29cce3f
 
 
 
 
 
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
from typing import Callable
import pandas as pd
import numpy as np


class NN:
    def __init__(
        self,
        epochs: int,
        hidden_size: int,
        learning_rate: float,
        test_size: float,
        activation: str,
        features: list[str],
        target: str,
        data: str,
    ):
        self.epochs = epochs
        self.hidden_size = hidden_size
        self.learning_rate = learning_rate
        self.test_size = test_size
        self.activation = activation
        self.features = features
        self.target = target
        self.data = data

        self.input_size = len(features)

        self.wh: np.array = None
        self.wo: np.array = None
        self.bh: np.array = None
        self.bo: np.array = None
        self.func_prime: Callable = None
        self.func: Callable = None
        self.df: pd.DataFrame = None
        self.X: pd.DataFrame = None
        self.y: pd.DataFrame = None

    def set_df(self, df: pd.DataFrame) -> None:
        assert isinstance(df, pd.DataFrame)
        self.df = df
        self.X = df[self.features]
        self.y = df[self.target]

    def set_func(self, f: Callable) -> None:
        assert isinstance(f, Callable)
        self.func = f

    def set_func_prime(self, f: Callable) -> None:
        assert isinstance(f, Callable)
        self.func_prime = f

    def set_bh(self, bh: np.array) -> None:
        self.bh = bh

    def set_wh(self, wh: np.array) -> None:
        self.wh = wh

    def set_bo(self, bo: np.array) -> None:
        self.bo = bo

    def set_wo(self, wo: np.array) -> None:
        self.wo = wo

    @classmethod
    def from_dict(cls, dct):
        """ Creates an instance of NN given a dictionary
        we can use this to make sure that the arguments are right
        """
        return cls(**dct)