Redux Study-- Source Code

Intro

This study base on the 4.0.4 version of Redux, which is implemented by TypeScript.

index.ts

The entrance of the codes, providing all the components API.

isCrushed() used to discover current environment is developing or production environment .

if the code is compressed and under production environment , then isCrushed.name will be type of String but the name will be changed to others

DP-Matrix Chain Order

Analyze Question

This is a simple example to understand matrix chain order in DP.
As we know, all the DP problem can be solve by three basic criteria

  1. find the optimized sub problem

    In matrix multiplication , the cost of multiplication of matrix is different between the different multi sequence.for e.g. we have 3 matrix

    A: 10X100

    B: 100x5

    C: 5x50

    then if we follow diff multiplication sequence

    for ((A1A2)A3) : A1A2=$10\times 100 \times 5 = 5000 $ A3=$10\times5\times50 = 2500$ tot: 7500

    for(A1(A2A3)): A2A3=$100 \times 5 \times 50 = 25000$ A1 = $10\times100\times50=50000$ tot:75000

    and thus its 10 times bigger for the last approach than the first approach

    and in DP we suppose if we already know the best solution for the matrix multiplication, for e.g. (A1A2A3A4)(A5A6A7) , if we separate them into subarrays ((A1A2A3)A4) (A5(A6A7)) the subarray it self should also be the optimized multiplication.

React-Redux 学习笔记

First of All

Redux并不是全局state管理唯一的方案,基于开发不同的工程,我们可以选择三种方案来解决props传递的问题。

  1. Hook
  2. React Context API
  3. and Redux

store

​ store 是本地state的集合,操作的state的都在里面,本地state指的是组件及其子组件的state.

reducer

​ reducer干的事很简单, 拿到一个state 和一个action返回 newstate

​ 我们可以总结为一个arrow funciton:

1
(state,action) => newState

reducer 需要一个初始状态,并且我们需要确保reducer在任何状态下都有state,缺失state的reducer是非常差劲的写法,初始状态示意如下

1
2
3
const initialState = {
something:0,
}

Recursive List 类题目的解法

举个栗子:

Given a linked list, swap every two adjacent nodes and return its head.

You may not modify the values in the list’s nodes, only nodes itself may be changed.

Huffman Coding

Method:

The Huffman coding which implies the greedy algorithm has its theory:

If you have a set of characters , and called it $C$ , has several characters which may or may not overlap each other.

Then lets say $C$ contains these characters: f,e,d,c,b,a

each character has different frequency which we will called it $F$ . Now we have a sequence like: f(5) ,e(9), d(16), c(12),b(13),a(45)

Now if we want to code these characters in order to get a better compression of the space we stored it , we have two choices

  1. we just simply code it into same length code
  2. we use the greedy method, which means we do our best to put the higher frequency character into short codes and lower frequency characters into the longer codes

A simple example with Socket

A simple example with Socket

Concepts:

  1. socket:

  2. thread

  3. I/O stream

    Output stream -> Sending buffer queue (SendQ)-> Network

    Network-> Receiving buffer queue (RecvQ)->Input Stream

Example:

Write a net program, include a server and client, client will send a string to the server, and server should print the string to the terminal, and return the length of string to the client, and finally the client should print the length sent from server. You should do it in TCP and UDP way.

Optimization for Directory Rendering in React

In Project “File Reader” to present a file manager-like react based web page, we are facing a problem, as we required for all the files from server, the json file for 37000 files tooks server almost 6s to respond and then the web page, depend on the cpu speed, tooks almost 9s to render, that is almost 15s to wait for user.

This is not a good result, for further investigation, we use console.log("performance fetch"+(t1-t0)/1000) to check the performance in seconds to see each step takes how long to finish.

we can see the result

Hands On ML

Chapter 2 End to End ML Project

Selected Performance Measure

Root Measure Square Error
$$
RMSE(X,h)=\sqrt{\frac{1}{m}(h(x^i)-y^i)^2}
$$
generally the preferred performance measure for regression tasks

Mean Absolute Error
$$
MAE(X,h) =\frac{1}{m}\displaystyle\sum_{i=1}^{m}|h(x^i)-y^i|
$$
If there are many outlier districts

Check assumptions

make sure the task is about regression or classification, actually, if a task is to put the exist data into exist category , it is the classification task.

A structed light based 3d reconstruction using combined circular phase shifting patterns

Presented by Dr. Yujia Zhang

Examples:

  • laser scanner

  • kinect

    -depth from focus ,depth from stereo

Concept :active vision

Passive triangulation:Stereo Vision

Active Triangulation:Structured Light 结构光

  • one of cameras replaced by light emitter
  • correspondence solved by searching in camera image
  • no geometric constraints

Structured light

  • any spatio-temporal pattern of light projected on a surface

Classification of structured light patterns

  • time multiplexing

    • high resolution
    • robust
    • only reconstruct static object
    • need large num of patterns

    Binary Codes for time multiplexing: $2^n$ strips

    N-ary Codes: decrease num of pattern but increased the basis of code and intensity(grey levels/colors)

DP-Matrix Chain Order

[Array] finding a number in 2D array

In a 2-D array (each sub-array has same length) every row is ascending from left to right

every col is ascending from up to down, find a number in this array, return a true/false to indicate found/not found

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public class Solution {
public boolean Find(int target, int[][] array) {
if (array.length == 0 || array[0].length == 0) return false;
int l = array.length - 1;
int k = array[0].length - 1;
if (target < array[0][0] || target > array[l][k]) return false;

for (int i = 0; i <= l; i++) {
if (array[i][0] > target) continue;
if (search(target, i, 0, k, array)) return true;
}

return false;

}


private boolean search(int target, int i, int min, int max, int[][] arr) {

if (max >= min) {
int mid = min+(max-min) / 2;
if (target == arr[i][mid]) return true;

if (arr[i][mid] > target) {
return search(target, i, min, mid-1, arr);
} else {
return search(target, i, mid+1, max, arr);
}
}
return false;

}
}

simplest solution, to traverse trough the first col of array in $m$ time and run a binary search for each row. total time complexity is $mlogn$.

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×