Steps to take for a comprehensive analysis.
Project background.
| # Load the data | |
| df = pd.read_csv('iris.csv') | |
| # Enumerate the classes | |
| unique_classes = sorted(list(set(df['variety']))) | |
| class_number = {y : x for x,y in enumerate(unique_classes)} | |
| df['variety'] = [class_number[x] for x in df['variety']] | |
| # Convert to numpy array and standardize the features | |
| data_X = df[['sepal.length', 'sepal.width', 'petal.length', 'petal.width']].values | |
| data_Y = df[['variety']].values | |
| data_X = data_X - np.min(data_X, axis=0) |
| # Set up the environment and collect the observation space and action space sizes | |
| env = gym.make("CartPole-v1") | |
| observation_space = env.observation_space.shape[0] | |
| action_space = env.action_space.n | |
| # The function for creating the initial population | |
| organism_creator = lambda : Organism([observation_space, 16, 16, 16, action_space], output='softmax') | |
| def simulate_and_evaluate(organism, trials=1): | |
| """ |
| # The function to create the initial population | |
| organism_creator = lambda : Organism([1, 16, 16, 16, 1], output='linear') | |
| # The function we are trying to learn. numpy doesn't have tau... | |
| true_function = lambda x : np.sin(2 * np.pi * x) # | |
| # The loss function, mean squared error, will serve as the negative fitness | |
| loss_function = lambda y_true, y_estimate : np.mean((y_true - y_estimate)**2) | |
| def simulate_and_evaluate(organism, replicates=1): | |
| """ | |
| Randomly generate `replicates` samples in [0,1], |
| import copy | |
| import numpy as np | |
| class Organism(): | |
| def __init__(self, dimensions, use_bias=True, output='softmax'): | |
| self.layers = [] | |
| self.biases = [] | |
| self.use_bias = use_bias | |
| self.output = self._activation(output) |
| # https://nlpforhackers.io/named-entity-extraction/ | |
| import os | |
| import string | |
| import collections | |
| import pickle | |
| from collections import Iterable | |
| from nltk.tag import ClassifierBasedTagger | |
| from nltk.chunk import ChunkParserI, conlltags2tree, tree2conlltags |
| " File: ~/.vimrc | |
| " | |
| " Author: Victor I. Afolabi | |
| syntax enable | |
| colorscheme desert | |
| " highlight Normal guibg=none | |
| " ============================================================================= |
Someone asked a question some weeks back about why size_of::<Option<T>> is always double. Answer is because of alignment.
C doesn't have the ability to directly represent complex Rust enum, hence, the need for a workaround. To understand that, let's take a look at how Option<i32> is represnted in C.
E.g. Given: