Skip to content

Instantly share code, notes, and snippets.

View vermorel's full-sized avatar

Joannes Vermorel vermorel

View GitHub Profile
@vermorel
vermorel / split-csv.ps1
Last active June 14, 2016 12:28
Split large CSV files into smaller files while preserving the headers
# Splitting large CSV files into smaller ones, preserving the headers
# By Joannes Vermorel, 2015-12-18
function Split-Csv
{
param
(
[string] $file,
[int] $maxLines
)
@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 / 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 / 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 / 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 / git-fetch-rebase-subdirectories.psh1
Created April 25, 2012 11:47
Iterate through subdirectories in PowerShell and perform 'git fetch' and 'git rebase' each time
<#
Iterate through all subdirectories, and perform Git fetch, then Git rebase
on each subdirectory.
Joannes Vermorel, 2012-04-25
#>
$initpath = get-location
foreach($path in get-childitem) {
if ($path.Attributes -eq "Directory") {
@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 / 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 / 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 / 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
{