Skip to content

Instantly share code, notes, and snippets.

View vermorel's full-sized avatar

Joannes Vermorel vermorel

View GitHub Profile
@vermorel
vermorel / DelegateHelper.cs
Last active September 7, 2023 06:06
C# utility method that converts a Delegate into a MethodInfo
using System.Reflection;
using System.Reflection.Emit;
public static class DelegateHelper
{
/// <summary>
/// Compile the 'Delegate' to a static method.
/// </summary>
public static MethodInfo CompileToMethod(Delegate del)
{
@vermorel
vermorel / MurmurHash3.cs
Created November 26, 2018 15:55
Fast MurmurHash3 in C#
using System;
using System.Collections.Generic;
using Xunit;
namespace MyMurmurHash
{
/// <summary>
/// Fast hash - non-crypto secure. Intended to detect data storage
/// corruption.
/// </summary>
@vermorel
vermorel / fast_convolve_1D.cpp
Last active April 10, 2024 12:31
Fast 1D convolution with AVX
// Fast 1D convolution with AXV
// By Joannes Vermorel, Lokad, January 2018
// Released under MIT license
#include <string.h>
#include <stdio.h>
#include <malloc.h>
/* A simple implementation of a 1D convolution that just iterates over
* scalar values of the input array.
@vermorel
vermorel / RandomForestC.cs
Created July 31, 2017 14:46
Classification. A monolithic random forest C# implementation. Ordinal and categorical variables
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using NUnit.Framework;
namespace Lokad
{
/// <summary>
@vermorel
vermorel / RandomForestR.cs
Last active July 31, 2017 14:44
Regression. A monolithic random forest C# implementation, categorical variables treated as ordinals
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using NUnit.Framework;
namespace Lokad
{
/// <summary>
/// A random forest tailored for regression, treading categorical variables as on ordinals.
@vermorel
vermorel / brainscript-helpers.cntk
Last active August 3, 2017 06:48
Handy bits of BrainScript code
# A constant 1D tensor that contains an enumeration 0 .. (count - 1).
Range(count) = Splice( array [0..(count-1)] ( i => Constant{i} ) )
# residual units
ResNet(InnerDim, OuterDim, INNODE) = {
L1 = DenseLayer {InnerDim, activation = ReLU, init = "gaussian"}( INNODE )
L2 = DenseLayer {OuterDim, activation = Pass, init = "gaussian"}( L1 )
ResUnit = ReLU(Plus(INNODE, L2))
}.ResUnit
@vermorel
vermorel / ZTransform.cs
Created July 6, 2017 08:57
C# Z-Transform, the discrete version of the Laplace transform
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace Lokad
{
/// <summary>
/// Z-Transform is the discrete version of the Laplace transform.
/// In their transformed form, the convolution of two distributions
/// is just the point-wise product of their Z-transform coefficients.
@vermorel
vermorel / Half.cs
Last active November 26, 2023 22:43
C# Half-precision data type
/// ================ Half.cs ====================
/// The code is free to use for any reason without any restrictions.
/// Ladislav Lang (2009), Joannes Vermorel (2017)
using System;
using System.Diagnostics;
using System.Globalization;
namespace SystemHalf
{
@vermorel
vermorel / NaiveBayes.cs
Last active April 28, 2017 13:30
Classification with naive Bayes
using System;
using System.Collections.Generic;
using System.Linq;
namespace Lokad
{
/// <summary>
/// Naive Bayesian classifier.
/// </summary>
/// <remarks>
@vermorel
vermorel / convert-daily.ps1
Last active April 4, 2016 18:23
Random expansion of monthly data into daily data
# Random expansion of monthly data into daily data
# Syntax: convert-daily "c:\LokadData\foo.tsv"
# Expected columns are Id, Date, Quantity
# By Joannes Vermorel, April 2016
function convert-daily
{
param
(
[string] $file