<commit_before>use std::hash::{Hasher, BuildHasher};
use super::{Projection, SparseProjection};
use geometry::RegularSpace;
use geometry::dimensions::Continuous;
use ndarray::Array1;


#[derive(Serialize, Deserialize)]
pub struct TileCoding<H: BuildHasher> {
    hasher_builder: H,
    n_tilings: usize,
    memory_size: usize,
}

impl<H: BuildHasher> TileCoding<H> {
    pub fn new(hasher_builder: H, n_tilings: usize, memory_size: usize) -> Self {
        TileCoding {
            hasher_builder: hasher_builder,
            n_tilings: n_tilings,
            memory_size: memory_size,
        }
    }
}

impl<H: BuildHasher> Projection<RegularSpace<Continuous>> for TileCoding<H> {
    fn project_onto(&self, input: &Vec<f64>, phi: &mut Array1<f64>) {
        for t in self.project_sparse(input).iter() {
            phi[*t] = 1.0;
        }
    }

    fn dim(&self) -> usize {
        unimplemented!()
    }

    fn size(&self) -> usize {
        self.memory_size as usize
    }<commit_msg>fix(TileCoding): use l2 norm in TileCoding rep<commit_after>use std::hash::{Hasher, BuildHasher};
use super::{Projection, SparseProjection};
use geometry::RegularSpace;
use geometry::norms::l2;
use geometry::dimensions::Continuous;
use ndarray::Array1;


#[derive(Clone, Serialize, Deserialize)]
pub struct TileCoding<H: BuildHasher> {
    hasher_builder: H,
    n_tilings: usize,
    memory_size: usize,
    activation: f64,
}

impl<H: BuildHasher> TileCoding<H> {
    pub fn new(hasher_builder: H, n_tilings: usize, memory_size: usize) -> Self {
        TileCoding {
            hasher_builder: hasher_builder,
            n_tilings: n_tilings,
            memory_size: memory_size,
            activation: 1.0/l2(&vec![1.0; n_tilings]),
        }
    }
}

impl<H: BuildHasher> Projection<RegularSpace<Continuous>> for TileCoding<H> {
    fn project_onto(&self, input: &Vec<f64>, phi: &mut Array1<f64>) {
        for t in self.project_sparse(input).iter() {
            phi[*t] = self.activation;
        }
    }

    fn dim(&self) -> usize {
        unimplemented!()
    }

    fn size(&self) -> usize {
        self.memory_size as usize
    }
{'fraction_non_alphanumeric': 0.13043478260869565, 'fraction_numerical': 0.010752688172043012, 'mean_word_length': 3.099616858237548, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7637877', 'n_tokens_mistral': 758, 'n_tokens_neox': 756, 'n_words': 156}