Skip to content

Instantly share code, notes, and snippets.

View XinyueZ's full-sized avatar
🙊
Make sense, don't touch

ChrisDEV XinyueZ

🙊
Make sense, don't touch
View GitHub Profile
@XinyueZ
XinyueZ / ml_octave_launch.json
Created December 24, 2021 21:19
ml_octave_launch
{
"configurations": [
{
"type": "OctaveDebugger",
"request": "launch",
"name": "Octave Program",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.m",
"octave": "octave-cli",
"sourceFolder": "${workspaceFolder}",
"autoTerminate": true,
@XinyueZ
XinyueZ / ml_softmaxRegression.m
Last active January 8, 2022 22:01
Softmax regression
disp("multi-class classification with softmax regression from scratch......");
function [h, display_array] = displayData(X, example_width)
%DISPLAYDATA Display 2D data in a nice grid
% [h, display_array] = DISPLAYDATA(X, example_width) displays 2D data
% stored in X in a nice grid. It returns the figure handle h and the
% displayed array if requested.
% Set example_width automatically if not passed in
if ~exist('example_width', 'var') || isempty(example_width)
@XinyueZ
XinyueZ / ml_num_grad_check.m
Last active December 23, 2021 23:17
The numerical gradient check
disp("The numerical gradient check......");
function W = randWeights(in, out)
epsilon_init = sqrt(6) / sqrt(in + out);
W = rand(in, out) * 2 * epsilon_init - epsilon_init;
endfunction
function numericalGrads = applyNumericalGradients(costFunc, nn_params)
% Apply partial derivative of costFunc with respect to the
% i-th input argument.
@XinyueZ
XinyueZ / ml_kNearestNeighbor.m
Last active December 13, 2021 16:35
k-nearest neighbors algorithm (Simple and plain implementation)
disp("k-nearest neighbors algorithm (Simple and plain implementation)");
function [prediction, selected_by_K, distances] = kNN(X, model, K, MODE)
% X is a feature vector to query data in model with nearest distance.
% model contains the "trained" data, actually for KNN we don't train and there aren't parameters,
% we compare distance with the ground-truth data.
% Last column of model is label column.
% K is the first K result to select.
% MODE for "regression" , "classification" or "sortOnly".
@XinyueZ
XinyueZ / ml_normalEquations.m
Last active January 2, 2022 16:14
The normal equations
disp("Use the normal equations without training to get linear regression weights...");
function W = randWeights(in, out)
epsilon_init = sqrt(6) / sqrt(in + out);
W = rand(in, out) * 2 * epsilon_init - epsilon_init;
endfunction
% Gen data with m rows and n feature columns.
m = 5000; % m rows data
n = 100; % input features numbers
@XinyueZ
XinyueZ / flutter-extension-stream-listener-setup.dart
Created November 30, 2019 15:05
flutter-extension-stream-listener-setup
extension StreamControllerExtension<T> on StreamController<T> {
setStreamListener(void onData(T event),
{Function onError, void onDone(), bool cancelOnError}) {
if (!this.hasListener) {
this.stream.listen(onData,
onError: onError, onDone: onDone, cancelOnError: cancelOnError);
}
}
}
@XinyueZ
XinyueZ / gist:2ca9301328a758cfbabce72eed05f77a
Created November 11, 2019 23:20
flutter_ Wrap_content
Wrap_content ,Wrap_content :
//use this as child
Wrap(
children: <Widget>[*your_child*])
Match_parent,Match_parent:
//use this as child
Container(
height: double.infinity,
@XinyueZ
XinyueZ / gist:6867112a18828e672ab974af462a450b
Created October 18, 2019 14:42
Some recyclerview stuff
https://gitee.com/shetj/codes/90wfc8hoqbnesdy3gvzkm14
@XinyueZ
XinyueZ / CoroutineTestRule.kt
Created October 16, 2019 22:18 — forked from AniketSK/CoroutineTestRule.kt
A test rule to allow testing coroutines that use the main dispatcher. Without this you'd run into "java.lang.IllegalStateException: Module with the Main dispatcher had failed to initialize. For tests Dispatchers.setMain from kotlinx-coroutines-test module can be used"
package com.aniketkadam.sharevideoshortcut
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement
$ sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"