วันอาทิตย์ที่ 28 มิถุนายน พ.ศ. 2569

Techniques for public accessing to private-IP servers

  • Peer-to-peer overlay network Services 

ZeroTierTailscale are not SSL VPN. They use UDP hole punching.

UDP hole punching is a technique that allows two devices behind NAT routers (such as home routers) to establish a direct peer-to-peer connection without requiring manual port forwarding.

Here’s how it works:

  1. Both devices contact a public coordination server
    • Suppose Device A is at your home and Device B is in another organization.
    • Both devices first communicate with a publicly reachable server operated by the VPN service (e.g., ZeroTier).
  2. The coordination server learns their public addresses
    • The server observes the public IP address and UDP port assigned by each device’s NAT router.
  3. The server tells each device how to reach the other
    • Device A learns Device B’s public IP and port, and vice versa.
  4. Both devices simultaneously send UDP packets to each other
    • When Device A sends a packet to Device B, its NAT router creates a temporary mapping (a “hole”) allowing return traffic.
    • Device B does the same.
    • Because both sides have opened these temporary holes, the packets can pass through the NATs, establishing a direct connection.

Device A ── NAT A ── Internet ── NAT B ── Device B

     ↑                                          ↑

     └───── simultaneous UDP packets ─────────┘

Why is it called “hole punching”?

Normally, NAT routers block unsolicited incoming packets. By sending outgoing UDP packets first, each device creates a temporary opening (“hole”) in its NAT table that allows packets from the other device to enter.

Advantages

  • No need to configure port forwarding on routers.
  • Enables direct peer-to-peer communication.
  • Lower latency than relaying traffic through a central server.

Limitations

UDP hole punching does not work with all NAT types. It usually succeeds with:

  • Full-cone NAT
  • Restricted-cone NAT
  • Port-restricted cone NAT

It may fail with:

  • Symmetric NAT (common in some enterprise networks and cellular networks)

When hole punching fails, services such as ZeroTierTailscaleand WebRTC applications often fall back to relaying traffic through intermediary servers.

The coordination protocol commonly used to discover public addresses is based on the STUN standard, while relay fallback often uses TURN servers.

2. Cloudflare tunnels 

It’s a free service requiring registered DNS name. Cloudflare Tunnel: does not use hole punching. It relies on the private server maintaining a long-lived outbound connection to Cloudflare edge server.

วันเสาร์ที่ 20 มิถุนายน พ.ศ. 2569

CNN based on spatiotemporal features

CRNN (Convolutional Recurrent Neural Network) and STGCN (Spatio-Temporal Graph Convolutional Network) are both deep learning architectures used to process spatio-temporal data (like videos or time-series networks). The main difference is how they model space: CRNNs treat spatial features as an image grid (using CNNs), while STGCNs treat space as an interconnected topology of specific points (using Graph Neural Networks).

CRNN (Convolutional Recurrent Neural Network)
CRNNs combine Convolutional Neural Networks (CNNs) for spatial feature extraction with Recurrent Neural Networks (RNNs) like LSTMs or GRUs for sequence processing. 
  • Spatial Processing: Applies 2D or 3D CNNs to extract abstract feature representations from regular grid data (like video frames or pixels).
  • Temporal Processing: Uses recurrent memory cells to capture dependencies over time.
  • Common Use Cases: Video classification, image captioning, optical character recognition (OCR), and audio/speech recognition. 
STGCN (Spatio-Temporal Graph Convolutional Network)
STGCNs apply Graph Convolutional Networks (GCNs) to handle non-Euclidean spatial data and pair them with Temporal Convolutional Networks (TCNs) or similar operations for the time domain. 
  • Spatial Processing: Treats data as a graph where entities are "nodes" and relationships are "edges" (e.g., tracking human skeleton joints like hands and knees).
  • Temporal Processing: Processes time sequences in parallel or via temporal convolutions rather than looping sequentially through an RNN.
  • Common Use Cases: Human action recognition using skeleton poses, traffic forecasting, and traffic-flow modeling. 

วันพฤหัสบดีที่ 18 มิถุนายน พ.ศ. 2569

Optimization of model parameters vs hyper parameters

In machine learning, you deal with two main types of optimization:

  • Model Optimization (Internal): Things like Gradient Descent. This optimizes the weights and biases of a model by calculating derivatives.

  • Hyperparameter Optimization (External): Things like Grid Search, Random Search, or Bayesian Optimization. This optimizes the configuration settings of a model (e.g., learning rate, depth of a tree, regularization strength) that you cannot learn directly via gradient descent.

Grid Search belongs to the second category. It treats hyperparameter tuning as a black-box optimization problem (or global search problem) where you want to find the combination of parameters that maximizes (or minimizes) an evaluation metric (like accuracy or RMSE).
Grid Search is an optimization technique, specifically a brute-force optimization method used for hyperparameter tuning in machine learning. Grid Search performs an exhaustive search over a manually specified subset of hyperparameter space:

  1. You define a "grid" of values for each hyperparameter (e.g., learning rate $\in \{0.01, 0.1\}$, max depth $\in \{3, 5, 7\}$).
  2. It evaluates every single possible combination on your validation set (e.g., via cross-validation).
  3. It selects the combination that yields the best performance score.


Pros and Cons of Grid Search as an Optimizer

  • Pros:
    • It is guaranteed to find the optimal combination within the grid you defined.
    • It is fully parallelizable (each combination can be evaluated independently).
  • Cons (The Optimization Trap):
    • It suffers heavily from the curse of dimensionality. If you have 5 hyperparameters and try 10 values for each, you have to train and evaluate $10^5 = 100,000$ models.
    • It wastes computational power exploring unpromising regions of the search space compared to smarter optimizers like Bayesian Optimization or Random Search.
While simple and brute-force, it is definitively a formal strategy for optimizing your model's hyperparameters.
===

## 1. Model Parameter Optimization Methods

These methods are the actual **optimizing algorithms** that update the internal weights (w) and biases (b) of a model during the training phase based on the calculated gradients.

### First-Order Optimization (Gradient-Based)

 * **Stochastic Gradient Descent (SGD):** The foundational method. It calculates the gradient of the loss function for a small batch (or a single sample) and takes a step in the direction of the steepest descent.

 * **Momentum:** An extension of SGD that accelerates the optimization by adding a fraction of the previous step's update vector. This helps "roll" past local minima and dampens oscillations.

 * **Adam (Adaptive Moment Estimation):** The current industry standard for deep learning. It computes adaptive learning rates for each individual parameter by tracking both the first moment (the mean) and the second moment (the uncentered variance) of the gradients.

### Second-Order Optimization (Curvature-Based)

 * **L-BFGS (Limited-memory Broyden–Fletcher–Goldfarb–Shanno):** A quasi-Newton method that estimates the Hessian matrix (the second derivative of the loss function). It is computationally heavy but highly effective for smaller datasets and traditional algorithms like logistic regression or CRFs.

## 2. Hyperparameter Optimization (HPO) Methods

These are the macro-level strategies used to search for the best external configurations (e.g., finding the best learning rate, number of layers, or dropout rate) *before* the inner parameter training loop begins.

### Traditional/Exhaustive Search

 * **Grid Search:** As discussed, it performs an exhaustive search over a manually specified grid of discrete values.

   * *Example:* Testing every combination of learning rates [0.1, 0.01] and batch sizes [32, 64].

 * **Random Search:** Instead of checking every single point on a grid, it randomly samples configurations from a specified statistical distribution over a fixed number of iterations. It is mathematically proven to be more efficient than grid search because it doesn't waste time evaluating unimportant hyperparameters.

### Informed/Sequential Search

 * **Bayesian Optimization:** A smart, sequential strategy. It builds a probabilistic model (a "surrogate model," often using Gaussian Processes) of the objective function based on past evaluation results. It uses this model to mathematically predict which hyperparameter combination is most promising to try next, balancing exploration and exploitation.

### Heuristic & Evolutionary Algorithms

 * **Genetic Algorithms (GA):** A population of hyperparameter sets is initialized. The best-performing sets are selected to "reproduce" (combine metrics) and undergo random "mutation" to create the next generation of hyperparameters.

### Early-Stopping Based Methods

 * **Hyperband:** An advanced variation of random search that uses a "successive halving" approach. It starts many training runs with random configurations simultaneously but only allocates a tiny resource budget (e.g., a few epochs) to them initially. It aggressively terminates poor performers early and funnels the remaining training budget into the most promising setups.

### Summary of the Workflow Hierarchy

```

[ Hyperparameter Optimization (e.g., Bayesian Optimization) ]

       │

       ▼  Chooses a setup (e.g., Learning Rate = 0.001)

       │

   ┌───┴───────────────────────────────────────────┐

   │ Inner Loop: Training Phase                    │

   │                                               │

   │ [ Model Parameter Optimization (e.g., Adam) ] │

   │       │                                       │

   │       ▼  Updates Weights and Biases           │

   │   (Minimizes Loss Function on Data)           │

   └───────────────────────────────────────────────┘


```