crocrodile.nn - Neural Network

Crocrodile Neural Network.

Base class for Crocrodile NN.

class crocrodile.nn.NeuralNetwork[source]

Base class for NN.

static array_to_csv(array, csv_path)[source]

Write array in csv_path CSV file.

calculate() → numpy.ndarray[source]

Calculate NN result by using :attr:NeuralNetwork.layers with multiple layers.

Renvoie

Output layer.

Type renvoyé

numpy.ndarray

change_files()[source]

Change files locations.

check_always_same()[source]

Check success rating on good moves and on bad moves.

check_difference()[source]

Check success rate on good moves and on bad moves and return it.

check_move(board, move)[source]

Generate inputs, calculate and return output.

check_move_with_transpos(board: str, move: str) → bool[source]

Check a move with transposition.

Generate inputs, calculate and return output.

Paramètres
  • board (str) – FEN of the board to check.

  • move (str) – Move who will be played.

Renvoie

Wether if move is interesting or not.

Type renvoyé

bool

check_test()[source]

Check NN on test dataset.

check_train()[source]

Check NN on train dataset.

clear() → None[source]

Clear layers.

static csv_to_array(csv_path)[source]

Read CSV file and return array.

full_calculate()[source]

Calculate NN result with all hidden layers.

generate() → None[source]

Generate new matrixes.

generate_inputs(board: str, move: str) → bool[source]

Generate inputs for move move in board.

Paramètres
  • board (str) – FEN of the board.

  • move (str) – UCI notation of the move to check.

Renvoie

False if this is a check, True else.

Type renvoyé

bool

genetic_configure()[source]

Configure genetic training algorithm.

genetic_random()[source]

Random NNs for genetic algorithm.

genetic_save(confirmation=True)[source]

Save genetic algorithm configuration.

genetic_train()[source]

Genetic training algorithm.

New training algorithm using a real genetic algorithm.

load_layers(nn: int) → None[source]

Load layers with a NN ID from nns/.

Paramètres

nn (int) – NN to load (nns/<nn>-….csv)

Renvoie

Nothing.

Type renvoyé

None

load_networks() → None[source]

Load networks from folder nns/

Renvoie

None

Type renvoyé

None

masters_check_train()[source]

Check NN on train dataset.

masters_genetic_train(masters_good_moves, masters_bad_moves, config)[source]

Genetic training algorithm.

New training algorithm using a real genetic algorithm.

masters_random()[source]

Random NNs for genetic masters training algorithm.

static normalisation(array)[source]

Normalisation.

old_calculate()[source]

Calculate NN result.

output()[source]

Return NN output.

test(list_good_moves: list, list_bad_moves: list) → tuple[source]

Test neural network. Used by basics training.

Paramètres
  • list_good_moves (list) – List of good moves at format [« <FEN>n<Good move> », « <FEN>n<Good move> »]

  • list_bad_moves (list) – List of bad moves at format [« <FEN>n<Bad move> », « <FEN>n<Bad move> »]

Renvoie

Tupple (Number of correct answers on good moves, Number of correct answers on bad moves)

Type renvoyé

tuple[int]

test_full()[source]

Test neural network on full files. Lists list_good_moves and list_bad_moves can be obtained from training files with open(« <path> »).read().split(« nn »). Standard format is [« <FEN>n<move> », « <FEN>n<move> »]

Paramètres
  • list_good_moves (list) – List of good moves at standard format

  • list_bad_moves (list) – List of bad moves at standard format

Renvoie

Number of correct answers on good moves, on bad moves

Type renvoyé

Tuple[int, int]

test_full_multiprocesses()[source]

Test neural network on full files with multi-processing. Lists list_good_moves and list_bad_moves can be obtained from training files with open(« <path> »).read().split(« nn »). Standard format is [« <FEN>n<move> », « <FEN>n<move> »]

Paramètres
  • list_good_moves (list) – List of good moves at standard format

  • list_bad_moves (list) – List of bad moves at standard format

Renvoie

Number of correct answers on good moves, on bad moves

Type renvoyé

Tuple[int, int]

test_new()[source]

Test neural network on new moves new_good_move and new_bad_moves. Standard format is [« <FEN>n<move> », « <FEN>n<move> »] Standard format for new_good_move is « <FEN>n<move> »

Paramètres
  • list_good_moves (list) – The new good move to test at standard format

  • list_bad_moves (list) – The new bad moves to test at standard format

Renvoie

Total number of correct answers on good moves, on bad moves

Type renvoyé

Tuple[int, int]

train()[source]

Train Neural Network.

train_settings = None
self.train_good = (
open(self.genetic_train_settings[« train_good »]).read().split(

« 

« )

) self.train_bad = (

open(self.genetic_train_settings[« train_bad »]).read().split( »

« )

) self.test_good = (

open(self.genetic_train_settings[« test_good »]).read().split( »

« )

) self.test_bad = (

open(self.genetic_train_settings[« test_bad »]).read().split( »

« )

)

crocrodile.nn.basics_train - Basics Training

Crocrodile Training.

Back to basics.

author

Virinas-code and ZeBox

class crocrodile.nn.basics_train.BasicsTrain[source]

Basics train - class for training Crocrodile.

Author

@ZeBox and Virinas-code

static array_to_csv(array, csv_path)[source]

Write array in csv_path CSV file.

ask() → dict[source]

Ask for inputs.

Paramètres

self (BasicsTrain) – Current BasicsTrain object.

Renvoie

Good moves file.

Type renvoyé

str

couple(matrix1: numpy.ndarray, matrix2: numpy.ndarray) → numpy.ndarray[source]

Couple two matrixes.

Paramètres
  • matrix1 (numpy.ndarray) – First matrix to couple.

  • matrix2 (numpy.ndarray) – Second matrix to couple.

Renvoie

A new matrix.

Type renvoyé

numpy.ndarray

couple_networks(worst_network: int, network1: int, network2: int) → None[source]

Couple two networks.

Paramètres
  • network1 (int) – First network indice

  • network2 (int) – Second network indice.

Renvoie

Nothing.

Type renvoyé

None.

couple_pawns(matrix1: numpy.ndarray, matrix2: numpy.ndarray) → numpy.ndarray[source]

Couple two pawn matrixes.

Paramètres
  • matrix1 (numpy.ndarray) – First matrix to couple.

  • matrix2 (numpy.ndarray) – Second matrix to couple.

Renvoie

A new matrix.

Type renvoyé

numpy.ndarray

couple_pieces(matrix1: numpy.ndarray, matrix2: numpy.ndarray) → numpy.ndarray[source]

Couple two pieces matrixes.

Paramètres
  • matrix1 (numpy.ndarray) – First matrix to couple.

  • matrix2 (numpy.ndarray) – Second matrix to couple.

Renvoie

A new matrix.

Type renvoyé

numpy.ndarray

generate() → None[source]

Generate empty networks and save them.

Renvoie

None

Type renvoyé

None

static generate_bad_moves(good_move_pos: str, good_moves_list, bad_moves_list)[source]

Generate bad moves for position.

Paramètres

good_move_pos (str) – Good move in position (FEN + good move)

load() → None[source]

Load neural networks from nns/ folder.

Renvoie

None

main(argv)[source]

Start training.

static parse_good_moves(good_moves_file: str) → list[source]

Parse good moves in good_moves_file. good_moves_file is only a file path.

Paramètres

good_moves_file (str) – Path to the good moves file.

Renvoie

The list of FENs + good move.

Type renvoyé

list

save() → None[source]

Save neural networks to nns/ folder.

Renvoie

None

train(new_good_move: str, new_bad_moves: str, param_good_moves: list, param_bad_moves: list) → float[source]

Train neural networks.

Renvoie

Mean performance at end.

Type renvoyé

float

crocrodile.nn.basics_train.main(argv)[source]

Start function called in init.

Paramètres

argv (list) – sys.argv

Renvoie

None

Type renvoyé

None

crocrodile.nn.load_network - Load Network

Crocrodile NNs.

Load network: Load network to use it with the client.

crocrodile.nn.masters_train - Masters Training

crocrodile.nn.nn_auto - Auto Neural Network Training

NN Auto.

Simple tool to create Crocrodile NN Training files.

crocrodile.nn.nn_random - Random Neural Networks Generator

crocrodile.nn.old_nn - Old Neural Network