[][src]Struct radiate_matrix_tree::tree::Tree

pub struct Tree<T: Clone> { /* fields omitted */ }

A tree struct to encapsulate a bidirectional binary tree.AsMut

Each node within the tree has three pointers to its parent, left, and right child.

This struct holds the root of the tree. The tree also contains a size which represents the number of nodes in the tree, an input size which is the size of the input vector (1D), and is used to generate nodes alone with the output options which is an owned vec of i32s represnting different outputs of the classification.

Implementations

impl<T: Clone> Tree<T>[src]

implement the tree

pub fn new() -> Self[src]

Create a new default Tree given an input size and a vec of possible outputs

Returns the newly created Tree with no root node, a size of 0 and an owned input_size and output_options.

pub fn from_slice(nodes: &mut [Option<T>]) -> Self[src]

build tree from node slice

pub fn iter_mut(&mut self) -> IterMut<T>[src]

return an in order iterator which allows for the nodes in the tree to be mutatued while iterating

pub fn level_order_iter(&self) -> LevelOrderIterator<T>[src]

Return a level order iterator Iterators over the tree from top to bottom, going from parent, to it's left child then it's right child. Each node that the iterator yields is a reference to a Node struct

pub fn in_order_iter(&self) -> InOrderIterator<T>[src]

Return an in order iterator Iterates over the tree in order, from left to right with the root in the middle (assuming balanced) Each node that the iterator yields is a reference to a Node struct

pub fn len(&self) -> usize[src]

the len of the tree is it's size, the numbr of nodes

pub fn update_size(&mut self)[src]

Update size from root node.

pub fn height(&self) -> i32[src]

return the height of the tree from the root

pub fn get(&self, index: usize) -> Option<&T>[src]

Get a node's element from the tree at a given index and return an option with either the node's element in it, or none.

pub fn get_mut(&mut self, index: usize) -> Option<&mut T>[src]

Get a node's element from the tree at a given index and return an option with either the node's element in it, or none.

pub fn get_node_mut(&mut self, index: usize) -> Option<&mut Node<T>>[src]

Get a node from the tree at a given index and return an option with either the node in it, or none.

pub fn index_of(&self, node: &Node<T>) -> usize[src]

Get the index of a given node in the tree

pub fn insert_random(&mut self, elem: T)[src]

Insert a node to the tree randomly and increase the size by 1.

pub fn display(&self)[src]

display the tree by calling the recursive display method within the node implementation at level 0. If no root node, panic!

pub fn balance(&mut self)[src]

Balance the tree by thin copying each node then calling a private recursive function to build the tree structure.

Return an option in order to use '?' instead of 'unwrap()' in the function body.

pub fn get_biased_level<'a>(&'a self) -> Vec<&'a Node<T>>[src]

get a vec of node references in a bised sense where nodes at a lower level are favored

pub fn get_biased_random_node<'a>(&'a self) -> &'a Node<T>[src]

Get a biased random node from the tree by gathering a biased random level towards the bottom of the tree, then returning a reference to the chosen node

pub fn shuffle_tree(&mut self, r: &mut ThreadRng)[src]

Shuffel the tree by gathering a list of the nodes then shuffling the list and then balancing the tree again from that list

impl Tree<NetNode>[src]

implement the tree

pub fn gut_random_node(&mut self, r: &mut ThreadRng)[src]

Gut a random node from the tree. Get a random index from the tree then give that node a new neural network.

pub fn edit_random_node_networks(
    &mut self,
    weight_mutate: f32,
    weight_transform: f32,
    layer_mutate: f32
)
[src]

Go through each of the nodes in the tree and randomly mutate the weights and biases within the network

pub fn asymmetry(&self) -> f32[src]

Compute the asymmetry for a single tree by adding the height times the neural network weight sum of the tree and putting it through the sine function to compress the number between (-1, 1)

pub fn propagate(&self, inputs: Matrix<f32>) -> u8[src]

Trait Implementations

impl<T: Clone> Clone for Tree<T>[src]

Return a new copy of the tree, calling deep copy from the root node and copying over the size, input size, and output options in the most effecient way.

impl<T: Clone> Debug for Tree<T>[src]

implemented a display function for the Tree just for easier debugging

impl<T: Clone> Default for Tree<T>[src]

implement a function for getting a base default Tree which is completetly empty There are multiple places within the struct implementation which will panic! if this default Tree is passed through it.

impl<T: Clone> Drop for Tree<T>[src]

Because the tree is made out of raw mutable pointers, if those pointers are not dropped, there is a severe memory leak, like possibly gigs of ram over only a few generations depending on the size of the generation This drop implementation will recursivley drop all nodes in the tree

impl Genome<Tree<NetNode>, TreeEnvionment> for Evtree[src]

fn crossover(
    one: &Evtree,
    two: &Evtree,
    settings: &Arc<RwLock<TreeEnvionment>>,
    crossover_rate: f32
) -> Option<Evtree>
[src]

one should be the more fit Evtree and two should be the less fit Evtree. This function should attemp to produce a Evtree which is no higher than the specified max height of a Evtree.

fn base(settings: &mut TreeEnvionment) -> Evtree[src]

Implement the base trait for the tree This provides a generic way to get a base tree for starting the evolution process Get the base tree type and return a randomly generated base tree created through the tree settings given to it at its new() call

fn distance(
    one: &Evtree,
    two: &Evtree,
    _settings: &Arc<RwLock<TreeEnvionment>>
) -> f32
[src]

takes in a Rc<RefCell<Self in order to make it simpler for the Generation to throw types it already has inside the function by simplmy cloing them. This function will drop the references to the Self traits at the end of this function's scope

impl<T: PartialEq + Clone> PartialEq<Tree<T>> for Tree<T>[src]

impl<T: Clone> Send for Tree<T>[src]

These must be implemneted for the tree or any type to be used within seperate threads. Because implementing the functions themselves is dangerious and unsafe and i'm not smart enough to do that from scratch, these "implmenetaions" will get rid of the error and realistically they don't need to be implemneted for the program to work

impl<T: Clone> StructuralPartialEq for Tree<T>[src]

impl<T: Clone> Sync for Tree<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for Tree<T> where
    T: RefUnwindSafe

impl<T> Unpin for Tree<T>

impl<T> UnwindSafe for Tree<T> where
    T: RefUnwindSafe + UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,