Struct genome::DNA

source ·
pub struct DNA {
    pub pool_size: u16,
    pub gene_size: u16,
    pub genes: Vec<Gene>,
}

Fields§

§pool_size: u16§gene_size: u16§genes: Vec<Gene>

Implementations§

source§

impl DNA

source

pub fn new(pool_size: u16, gene_size: u16) -> DNA

Constructs a new DNA.

§Examples
use genome::DNA;

let dna = DNA::new(2, 2);
source

pub fn is_valid(dna_str: String) -> bool

Check if current DNA string is valid.

§Examples
use genome::DNA;
let dna = DNA::new(2, 2);

let is_valid = DNA::is_valid(dna.to_string());
source

pub fn merge(left_dna: DNA, right_dna: DNA, mutate: bool) -> Option<DNA>

Merge two DNA into one

§Examples
use genome::DNA;

let dna1 = DNA::new(2, 2);
let dna2 = DNA::new(2, 2);

let merged = DNA::merge(dna1, dna2, false);
source

pub fn compare(left_dna: DNA, right_dna: DNA) -> f64

Compare two DNA similarity, return the percentage of same genes

§Examples
use genome::DNA;

let dna1 = DNA::new(256, 2);
let dna_str = dna1.to_string();
let dna2 = DNA::new(256, 2);

let merged = DNA::merge(dna1, dna2, false).unwrap();

let is_parent = DNA::compare(DNA::from(dna_str), merged) > 0.3;
source

pub fn to_latent_vec(&self) -> Vec<f32>

Convert DNA to GAN latent vector

§Examples
use genome::DNA;

let dna1 = DNA::new(2, 2);

let latent = dna1.to_latent_vec();
source

pub fn to_string(&self) -> String

Convert DNA to string

§Examples
use genome::DNA;

let dna1 = DNA::new(2, 2);

let dna1_str = dna1.to_string();
source

pub fn get_sum(&self) -> f32

Get checksum for the dna, return back f32 sum of all genes.

§Examples
use genome::DNA;

let dna1 = DNA::new(2, 2);

let dna1_str = dna1.get_sum();

Trait Implementations§

source§

impl From<DNA> for String

Convert DNA to string

§Examples

use genome::DNA;

let dna1 = DNA::new(2, 2);

let dna1_str = String::from(dna1);
source§

fn from(dna: DNA) -> String

Converts to this type from the input type.
source§

impl From<String> for DNA

Convert DNA to string

§Examples

use genome::DNA;

let dna1 = DNA::new(2, 2);
let dna1_str = dna1.to_string();

let dna_copy = DNA::from(dna1_str);
source§

fn from(dna: String) -> DNA

Converts to this type from the input type.

Auto Trait Implementations§

§

impl RefUnwindSafe for DNA

§

impl Send for DNA

§

impl Sync for DNA

§

impl Unpin for DNA

§

impl UnwindSafe for DNA

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

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

source§

fn vzip(self) -> V