C#基于ScottPlot进行可视化

news2024/9/22 17:19:53

前言

上一篇文章跟大家分享了用NumSharp实现简单的线性回归,但是没有进行可视化,可能对拟合的过程没有直观的感受,因此今天跟大家介绍一下使用C#基于Scottplot进行可视化,当然Python的代码,我也会同步进行可视化。

Python代码进行可视化

Python代码用matplotlib做了可视化,我就不具体介绍了。

修改之后的python代码如下:

#The optimal values of m and b can be actually calculated with way less effort than doing a linear regression. 
#this is just to demonstrate gradient descent

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation


# y = mx + b
# m is slope, b is y-intercept
def compute_error_for_line_given_points(b, m, points):
    totalError = 0
    for i in range(0, len(points)):
        x = points[i, 0]
        y = points[i, 1]
        totalError += (y - (m * x + b)) ** 2
    return totalError / float(len(points))

def step_gradient(b_current, m_current, points, learningRate):
    b_gradient = 0
    m_gradient = 0
    N = float(len(points))
    for i in range(0, len(points)):
        x = points[i, 0]
        y = points[i, 1]
        b_gradient += -(2/N) * (y - ((m_current * x) + b_current))
        m_gradient += -(2/N) * x * (y - ((m_current * x) + b_current))
    new_b = b_current - (learningRate * b_gradient)
    new_m = m_current - (learningRate * m_gradient)
    return [new_b, new_m]

def gradient_descent_runner(points, starting_b, starting_m, learning_rate, num_iterations):
    b = starting_b
    m = starting_m
    args_data = []
    for i in range(num_iterations):
        b, m = step_gradient(b, m, np.array(points), learning_rate)
        args_data.append((b,m))
    return args_data

if __name__ == '__main__':
     points = np.genfromtxt("data.csv", delimiter=",")
     learning_rate = 0.0001
     initial_b = 0 # initial y-intercept guess
     initial_m = 0 # initial slope guess
     num_iterations = 10
     print ("Starting gradient descent at b = {0}, m = {1}, error = {2}".format(initial_b, initial_m, compute_error_for_line_given_points(initial_b, initial_m, points)))
     print ("Running...")
     args_data = gradient_descent_runner(points, initial_b, initial_m, learning_rate, num_iterations)
     
     b = args_data[-1][0]
     m = args_data[-1][1]

     print ("After {0} iterations b = {1}, m = {2}, error = {3}".format(num_iterations, b, m, compute_error_for_line_given_points(b, m, points)))
    
     data = np.array(points).reshape(100,2)
     x1 = data[:,0]
     y1 = data[:,1]
     
     x2 = np.linspace(20, 80, 100)
     y2 = initial_m * x2 + initial_b

     data2 = np.array(args_data)
     b_every = data2[:,0]
     m_every = data2[:,1]

     # 创建图形和轴
     fig, ax = plt.subplots()
     line1, = ax.plot(x1, y1, 'ro')
     line2, = ax.plot(x2,y2)

     # 添加标签和标题
     plt.xlabel('x')
     plt.ylabel('y')
     plt.title('Graph of y = mx + b')

     # 添加网格
     plt.grid(True)

    # 定义更新函数
     def update(frame):
        line2.set_ydata(m_every[frame] * x2 + b_every[frame])
        ax.set_title(f'{frame} Graph of y = {m_every[frame]:.2f}x + {b_every[frame]:.2f}')
    
# 创建动画
animation = FuncAnimation(fig, update, frames=len(data2), interval=500)

# 显示动画
plt.show()

实现的效果如下所示:

python代码的可视化

image-20240113200232614

C#代码进行可视化

这是本文重点介绍的内容,本文的C#代码通过Scottplot进行可视化。

Scottplot简介

ScottPlot 是一个免费的开源绘图库,用于 .NET,可以轻松以交互方式显示大型数据集。

控制台程序可视化

首先我先介绍一下在控制台程序中进行可视化。

首先添加Scottplot包:

image-20240113201207374

将上篇文章中的C#代码修改如下:

using NumSharp;

namespace LinearRegressionDemo
{
    internal class Program
    {    
        static void Main(string[] args)
        {   
            //创建double类型的列表
            List<double> Array = new List<double>();
            List<double> ArgsList = new List<double>();

            // 指定CSV文件的路径
            string filePath = "你的data.csv路径";

            // 调用ReadCsv方法读取CSV文件数据
            Array = ReadCsv(filePath);

            var array = np.array(Array).reshape(100,2);

            double learning_rate = 0.0001;
            double initial_b = 0;
            double initial_m = 0;
            double num_iterations = 10;

            Console.WriteLine($"Starting gradient descent at b = {initial_b}, m = {initial_m}, error = {compute_error_for_line_given_points(initial_b, initial_m, array)}");
            Console.WriteLine("Running...");
            ArgsList = gradient_descent_runner(array, initial_b, initial_m, learning_rate, num_iterations);
            double b = ArgsList[ArgsList.Count - 2];
            double m = ArgsList[ArgsList.Count - 1];
            Console.WriteLine($"After {num_iterations} iterations b = {b}, m = {m}, error = {compute_error_for_line_given_points(b, m, array)}");
            Console.ReadLine();

            var x1 = array[$":", 0];
            var y1 = array[$":", 1];
            var y2 = m * x1 + b;

            ScottPlot.Plot myPlot = new(400, 300);
            myPlot.AddScatterPoints(x1.ToArray<double>(), y1.ToArray<double>(), markerSize: 5);
            myPlot.AddScatter(x1.ToArray<double>(), y2.ToArray<double>(), markerSize: 0);
            myPlot.Title($"y = {m:0.00}x + {b:0.00}");

            myPlot.SaveFig("图片.png");
       
        }

        static List<double> ReadCsv(string filePath)
        {
            List<double> array = new List<double>();
            try
            {
                // 使用File.ReadAllLines读取CSV文件的所有行
                string[] lines = File.ReadAllLines(filePath);             

                // 遍历每一行数据
                foreach (string line in lines)
                {
                    // 使用逗号分隔符拆分每一行的数据
                    string[] values = line.Split(',');

                    // 打印每一行的数据
                    foreach (string value in values)
                    {
                        array.Add(Convert.ToDouble(value));
                    }                  
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("发生错误: " + ex.Message);
            }
            return array;
        }

        public static double compute_error_for_line_given_points(double b,double m,NDArray array)
        {
            double totalError = 0;
            for(int i = 0;i < array.shape[0];i++)
            {
                double x = array[i, 0];
                double y = array[i, 1];
                totalError += Math.Pow((y - (m*x+b)),2);
            }
            return totalError / array.shape[0];
        }

        public static double[] step_gradient(double b_current,double m_current,NDArray array,double learningRate)
        {
            double[] args = new double[2];
            double b_gradient = 0;
            double m_gradient = 0;
            double N = array.shape[0];

            for (int i = 0; i < array.shape[0]; i++)
            {
                double x = array[i, 0];
                double y = array[i, 1];
                b_gradient += -(2 / N) * (y - ((m_current * x) + b_current));
                m_gradient += -(2 / N) * x * (y - ((m_current * x) + b_current));
            }

            double new_b = b_current - (learningRate * b_gradient);
            double new_m = m_current - (learningRate * m_gradient);
            args[0] = new_b;
            args[1] = new_m;

            return args;
        }

        public static List<double> gradient_descent_runner(NDArray array, double starting_b, double starting_m, double learningRate,double num_iterations)
        {
            double[] args = new double[2];
            List<double> argsList = new List<double>();
            args[0] = starting_b;
            args[1] = starting_m;

            for(int i = 0 ; i < num_iterations; i++) 
            {
                args = step_gradient(args[0], args[1], array, learningRate);
                argsList.AddRange(args);
            }

            return argsList;
        }


    }
}

然后得到的图片如下所示:

image-20240113202345301

在以上代码中需要注意的地方:

  var x1 = array[$":", 0];
  var y1 = array[$":", 1];

是在使用NumSharp中的切片,x1表示所有行的第一列,y1表示所有行的第二列。

当然我们不满足于只是保存图片,在控制台应用程序中,再添加一个 ScottPlot.WinForms包:

image-20240113202751162

右键控制台项目选择属性,将目标OS改为Windows:

image-20240113212334704

将上述代码中的

  myPlot.SaveFig("图片.png");

修改为:

 var viewer = new ScottPlot.FormsPlotViewer(myPlot);
 viewer.ShowDialog();

再次运行结果如下:

image-20240113203022718

winform进行可视化

我也想像Python代码中那样画动图,因此做了个winform程序进行演示。

首先创建一个winform,添加ScottPlot.WinForms包,然后从工具箱中添加FormsPlot这个控件:

image-20240113205227384

有两种方法实现,第一种方法用了定时器:

using NumSharp;
namespace WinFormDemo
{
    public partial class Form1 : Form
    {
        System.Windows.Forms.Timer updateTimer = new System.Windows.Forms.Timer();
        int num_iterations;
        int count = 0;
        NDArray? x1, y1, b_each, m_each;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            StartLinearRegression();
        }

        public void StartLinearRegression()
        {
            //创建double类型的列表
            List<double> Array = new List<double>();
            List<double> ArgsList = new List<double>();

            // 指定CSV文件的路径
            string filePath = "你的data.csv路径";

            // 调用ReadCsv方法读取CSV文件数据
            Array = ReadCsv(filePath);

            var array = np.array(Array).reshape(100, 2);

            double learning_rate = 0.0001;
            double initial_b = 0;
            double initial_m = 0;
            num_iterations = 10;

            ArgsList = gradient_descent_runner(array, initial_b, initial_m, learning_rate, num_iterations);

            x1 = array[$":", 0];
            y1 = array[$":", 1];

            var argsArr = np.array(ArgsList).reshape(num_iterations, 2);
            b_each = argsArr[$":", 0];
            m_each = argsArr[$":", 1];

            double b = b_each[-1];
            double m = m_each[-1];
            var y2 = m * x1 + b;

            formsPlot1.Plot.AddScatterPoints(x1.ToArray<double>(), y1.ToArray<double>(), markerSize: 5);
            //formsPlot1.Plot.AddScatter(x1.ToArray<double>(), y2.ToArray<double>(), markerSize: 0);
            formsPlot1.Render();


        }

        static List<double> ReadCsv(string filePath)
        {
            List<double> array = new List<double>();
            try
            {
                // 使用File.ReadAllLines读取CSV文件的所有行
                string[] lines = File.ReadAllLines(filePath);

                // 遍历每一行数据
                foreach (string line in lines)
                {
                    // 使用逗号分隔符拆分每一行的数据
                    string[] values = line.Split(',');

                    // 打印每一行的数据
                    foreach (string value in values)
                    {
                        array.Add(Convert.ToDouble(value));
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("发生错误: " + ex.Message);
            }
            return array;
        }

        public static double compute_error_for_line_given_points(double b, double m, NDArray array)
        {
            double totalError = 0;
            for (int i = 0; i < array.shape[0]; i++)
            {
                double x = array[i, 0];
                double y = array[i, 1];
                totalError += Math.Pow((y - (m * x + b)), 2);
            }
            return totalError / array.shape[0];
        }

        public static double[] step_gradient(double b_current, double m_current, NDArray array, double learningRate)
        {
            double[] args = new double[2];
            double b_gradient = 0;
            double m_gradient = 0;
            double N = array.shape[0];

            for (int i = 0; i < array.shape[0]; i++)
            {
                double x = array[i, 0];
                double y = array[i, 1];
                b_gradient += -(2 / N) * (y - ((m_current * x) + b_current));
                m_gradient += -(2 / N) * x * (y - ((m_current * x) + b_current));
            }

            double new_b = b_current - (learningRate * b_gradient);
            double new_m = m_current - (learningRate * m_gradient);
            args[0] = new_b;
            args[1] = new_m;

            return args;
        }

        public static List<double> gradient_descent_runner(NDArray array, double starting_b, double starting_m, double learningRate, double num_iterations)
        {
            double[] args = new double[2];
            List<double> argsList = new List<double>();
            args[0] = starting_b;
            args[1] = starting_m;

            for (int i = 0; i < num_iterations; i++)
            {
                args = step_gradient(args[0], args[1], array, learningRate);
                argsList.AddRange(args);
            }

            return argsList;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            // 初始化定时器
            updateTimer.Interval = 1000; // 设置定时器触发间隔(毫秒)
            updateTimer.Tick += UpdateTimer_Tick;
            updateTimer.Start();
        }

        private void UpdateTimer_Tick(object? sender, EventArgs e)
        {
            if (count >= num_iterations)
            {
                updateTimer.Stop();
            }
            else
            {
                UpdatePlot(count);
            }

            count++;
        }

        public void UpdatePlot(int count)
        {

            double b = b_each?[count];
            double m = m_each?[count];

            var y2 = m * x1 + b;

            formsPlot1.Plot.Clear();
            formsPlot1.Plot.AddScatterPoints(x1?.ToArray<double>(), y1?.ToArray<double>(), markerSize: 5);
            formsPlot1.Plot.AddScatter(x1?.ToArray<double>(), y2.ToArray<double>(), markerSize: 0);
            formsPlot1.Plot.Title($"第{count + 1}次迭代:y = {m:0.00}x + {b:0.00}");
            formsPlot1.Render();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            updateTimer.Stop();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

简单介绍一下思路,首先创建List<double> argsList用来保存每次迭代生成的参数b、m,然后用

           var argsArr = np.array(ArgsList).reshape(num_iterations, 2);  

argsList通过np.array()方法转化为NDArray,然后再调用reshape方法,转化成行数等于迭代次数,列数为2,即每一行对应一组参数值b、m。

            b_each = argsArr[$":", 0];
            m_each = argsArr[$":", 1];

argsArr[$":", 0]表示每一行中第一列的值,也就是每一个b,argsArr[$":", 1]表示每一行中第二列的值。

            double b = b_each[-1];
            double m = m_each[-1];

b_each[-1]用了NumSharp的功能表示b_each最后一个元素。

实现效果如下所示:

winform绘图效果1

另一种方法可以通过异步实现:

using NumSharp;

namespace WinFormDemo
{
    public partial class Form2 : Form
    {      
        int num_iterations;
        NDArray? x1, y1, b_each, m_each;
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            StartLinearRegression();
        }

        public void StartLinearRegression()
        {
            //创建double类型的列表
            List<double> Array = new List<double>();
            List<double> ArgsList = new List<double>();

            // 指定CSV文件的路径
            string filePath = "你的data.csv路径";

            // 调用ReadCsv方法读取CSV文件数据
            Array = ReadCsv(filePath);

            var array = np.array(Array).reshape(100, 2);

            double learning_rate = 0.0001;
            double initial_b = 0;
            double initial_m = 0;
            num_iterations = 10;

            ArgsList = gradient_descent_runner(array, initial_b, initial_m, learning_rate, num_iterations);

            x1 = array[$":", 0];
            y1 = array[$":", 1];

            var argsArr = np.array(ArgsList).reshape(num_iterations, 2);
            b_each = argsArr[$":", 0];
            m_each = argsArr[$":", 1];

            double b = b_each[-1];
            double m = m_each[-1];
            var y2 = m * x1 + b;

            formsPlot1.Plot.AddScatterPoints(x1.ToArray<double>(), y1.ToArray<double>(), markerSize: 5);      
            formsPlot1.Render();
        }

        static List<double> ReadCsv(string filePath)
        {
            List<double> array = new List<double>();
            try
            {
                // 使用File.ReadAllLines读取CSV文件的所有行
                string[] lines = File.ReadAllLines(filePath);

                // 遍历每一行数据
                foreach (string line in lines)
                {
                    // 使用逗号分隔符拆分每一行的数据
                    string[] values = line.Split(',');

                    // 打印每一行的数据
                    foreach (string value in values)
                    {
                        array.Add(Convert.ToDouble(value));
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("发生错误: " + ex.Message);
            }
            return array;
        }

        public static double compute_error_for_line_given_points(double b, double m, NDArray array)
        {
            double totalError = 0;
            for (int i = 0; i < array.shape[0]; i++)
            {
                double x = array[i, 0];
                double y = array[i, 1];
                totalError += Math.Pow((y - (m * x + b)), 2);
            }
            return totalError / array.shape[0];
        }

        public static double[] step_gradient(double b_current, double m_current, NDArray array, double learningRate)
        {
            double[] args = new double[2];
            double b_gradient = 0;
            double m_gradient = 0;
            double N = array.shape[0];

            for (int i = 0; i < array.shape[0]; i++)
            {
                double x = array[i, 0];
                double y = array[i, 1];
                b_gradient += -(2 / N) * (y - ((m_current * x) + b_current));
                m_gradient += -(2 / N) * x * (y - ((m_current * x) + b_current));
            }

            double new_b = b_current - (learningRate * b_gradient);
            double new_m = m_current - (learningRate * m_gradient);
            args[0] = new_b;
            args[1] = new_m;

            return args;
        }

        public static List<double> gradient_descent_runner(NDArray array, double starting_b, double starting_m, double learningRate, double num_iterations)
        {
            double[] args = new double[2];
            List<double> argsList = new List<double>();
            args[0] = starting_b;
            args[1] = starting_m;

            for (int i = 0; i < num_iterations; i++)
            {
                args = step_gradient(args[0], args[1], array, learningRate);
                argsList.AddRange(args);
            }

            return argsList;
        }

        private void Form2_Load(object sender, EventArgs e)
        {

        }

        public async Task UpdateGraph()
        {
            for (int i = 0; i < num_iterations; i++)
            {
                double b = b_each?[i];
                double m = m_each?[i];
                var y2 = m * x1 + b;

                formsPlot1.Plot.Clear();
                formsPlot1.Plot.AddScatterPoints(x1?.ToArray<double>(), y1?.ToArray<double>(), markerSize: 5);
                formsPlot1.Plot.AddScatter(x1?.ToArray<double>(), y2.ToArray<double>(), markerSize: 0);
                formsPlot1.Plot.Title($"第{i + 1}次迭代:y = {m:0.00}x + {b:0.00}");
                formsPlot1.Render();
           
                await Task.Delay(1000);
            }


        }

        private async void button2_Click(object sender, EventArgs e)
        {
            await UpdateGraph();
        }
    }
}

点击更新按钮开始执行异步任务:

 private async void button2_Click(object sender, EventArgs e)
        {
            await UpdateGraph();
        }
 public async Task UpdateGraph()
        {
            for (int i = 0; i < num_iterations; i++)
            {
                double b = b_each?[i];
                double m = m_each?[i];
                var y2 = m * x1 + b;

                formsPlot1.Plot.Clear();
                formsPlot1.Plot.AddScatterPoints(x1?.ToArray<double>(), y1?.ToArray<double>(), markerSize: 5);
                formsPlot1.Plot.AddScatter(x1?.ToArray<double>(), y2.ToArray<double>(), markerSize: 0);
                formsPlot1.Plot.Title($"第{i + 1}次迭代:y = {m:0.00}x + {b:0.00}");
                formsPlot1.Render();
           
                await Task.Delay(1000);
            }

实现效果如下:

winform绘图效果2

image-20240113210320131

总结

本文以一个控制台应用与一个winform程序为例向大家介绍了C#如何基于ScottPlot进行数据可视化,并介绍了实现动态绘图的两种方式,一种是使用定时器,另一种是使用异步操作,希望对你有所帮助。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1381216.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【SQL注入】SQLMAP v1.7.11.1 汉化版

下载链接 【SQL注入】SQLMAP v1.7.11.1 汉化版 简介 SQLMAP是一款开源的自动化SQL注入工具&#xff0c;用于扫描和利用Web应用程序中的SQL注入漏洞。它在安全测试领域被广泛应用&#xff0c;可用于检测和利用SQL注入漏洞&#xff0c;以验证应用程序的安全性。 SQL注入是一种…

脱离于ASP.NET 和Visual Studio编辑Razor脚本

Razor Pad是一个编辑Razor脚本的工具&#xff0c;脱离于ASP.NET 和Visual Studio。 github地址&#xff1a;https://github.com/RazorPad/RazorPad 如果在编译源码时出现&#xff1a;签名时出错: 未能对 bin\Debug\app.publish\RazorPad.exe 签名。SignTool Error: No certifi…

myql进阶-一条查询sql在mysql的执行过程

目录 1. 流程图 2. 各个过程 2.1 连接器 2.2 分析器 2.3 优化器 2.4 执行器 2.5 注意点 1. 流程图 2. 各个过程 假设我们执行一条sql语句如下&#xff1a; select * from t_good where good_id 1 2.1 连接器 首先我们会和mysql建立连接&#xff0c;此时就会执行到连接…

Java+Mysql存储过程生成订单序列号

Mysql存储过程生成唯一订单号 直接上代码&#xff01;&#xff01; 1.创建存储过程 CREATE DEFINERrootlocalhost PROCEDURE getOrderSerialNo(# 前缀in orderPrefix varchar(64), # 返回结果out result int) BEGIN# 当前流水号declare curOrderNo int;# 默认值为0declare e…

【问题探讨】基于非支配排序的蜣螂优化算法NSDBO求解微电网多目标优化调度研究

目录 主要内容 模型研究 结果一览 下载链接 主要内容 该模型以环境保护成本和运行成本为双目标构建了微电网优化调度模型&#xff0c;模型目标函数和约束条件复现文献《基于改进粒子群算法的微电网多目标优化调度》&#xff0c;程序的特点是采用非支配排序的蜣螂…

学习selenium+python使用 XPath 表达式来实现找到目标元素时智能封装等待,执行测试代码启动Chrome浏览器后,地址栏只显示data;

背景 学习使用 XPath 表达式来实现找到目标元素时智能封装等待执行测试代码启动Chrome浏览器后&#xff0c;地址栏只显示data&#xff1b; 代码如下 import unittest from selenium import webdriver from selenium.common.exceptions import NoSuchElementException from …

Java SE入门及基础(11)

程序调试 1. 什么是程序调试 当程序出现问题时&#xff0c;我们希望程序能够暂停下来&#xff0c;然后通过我们操作使代码逐行执行&#xff0c;观察整个过程中变量的变化是否按照我们设计程序的思维变化&#xff0c;从而找问题并解决问题&#xff0c;这个过程称之为程序调试…

ftp安装与配置 云服务器 CentOS7

1、FTP的安装 #安装 yum install -y vsftpd#设置开机启动 systemctl enable vsftpd.service#启动 systemctl start vsftpd.service#停止 systemctl stop vsftpd.service#查看状态 systemctl status vsftpd.service 2、配置FTP #修改前先进行备份文件 cp /etc/vsftpd/vsftpd…

LeetCode264. 丑数 II(相关话题:多重指针动态规划)

题目描述 给你一个整数 n &#xff0c;请你找出并返回第 n 个 丑数 。丑数 就是质因子只包含 2、3 和 5 的正整数。 示例 1&#xff1a; 输入&#xff1a;n 10 输出&#xff1a;12 解释&#xff1a;[1, 2, 3, 4, 5, 6, 8, 9, 10, 12] 是由前 10 个丑数组成的序列。示例 2&am…

物联网协议Coap之Core和NetWork简介

目录 前言 一、Coap的Core包 1、Coap对象 2、Message对象 3、Request对象 4、Response对象 二、Coap的NetWork调试 1、UDP运行模式 2、Network消息接收 3、Sender线程发送数据 三、总结 前言 在之前的博文中&#xff0c;对Californium中Coap的实现进行了简要的介绍&a…

31 树的存储结构二

DIsplay() 递归显示 :图示 求树的高度时&#xff0c;递归的技巧 在递归的过程中&#xff1a;ret单独和任意一个子树的子高度比较&#xff0c;如果ret<max&#xff0c;retmax ------------- 注意&#xff1a;组织链表和子链表的【元素类型】都是TLNode* 链表都要先通过TLNod…

Matlab数学建模算法之模拟退火算法(SA)详解

&#x1f517; 运行环境&#xff1a;Matlab &#x1f6a9; 撰写作者&#xff1a;左手の明天 &#x1f947; 精选专栏&#xff1a;《python》 &#x1f525; 推荐专栏&#xff1a;《算法研究》 &#x1f510;#### 防伪水印——左手の明天 ####&#x1f510; &#x1f497; 大家…

分布式事务:构建无障碍的云原生应用的完美解决方案

目录 一、前言 二、分布式事务概述 2.1 什么是分布式事务 2.2 分布式事务的挑战 2.3 分布式事务的分类 三、传统解决方案分析 3.1 两阶段提交协议&#xff08;2PC&#xff09; 3.2 三阶段提交协议&#xff08;3PC&#xff09; 3.3 补偿事务 3.4 其他传统解决方案 四…

什么是梅尼埃病?

梅尼埃病&#xff08;Meniere’s Disease&#xff0c;MD&#xff09;作为耳鼻咽喉科常见的眩晕疾病&#xff0c;是一种原因不明的、以膜迷路积水为主要病理特征的内耳疾病&#xff0c;临床表现为反复的发作性眩晕、波动性听力下降、耳鸣和耳闷胀感&#xff0c;发病率约为5~20/1…

paypal贝宝怎么绑卡支付

一、PayPal是什么 PayPal是一个很多国家地区通用的支付渠道&#xff0c;我们可以把它理解为一项在线服务&#xff0c;相当于美国版的支付宝。你可以通过PayPal进行汇款和收款&#xff0c;相比传统的电汇和西联那类的汇款方式&#xff0c;PayPal更加简单和容易&#xff0c;被很…

WebRTC入门:基础的核心协议与概念(二十三)

简介: CSDN博客专家,专注Android/Linux系统,分享多mic语音方案、音视频、编解码等技术,与大家一起成长! 优质专栏:Audio工程师进阶系列【原创干货持续更新中……】🚀 优质专栏:多媒体系统工程师系列【原创干货持续更新中……】🚀 人生格言: 人生从来没有捷径,只…

如何将.NET 8.0的ASP.NET Core Web API部署成Windows服务

写在前面 前面写了一篇关于将.NET应用转换成Windows服务的方法&#xff0c;其实真正的目的是为了探索如何将Asp.Net Core Web Api 部署成Windows 服务。基于上一篇的基础&#xff0c;只需把创建 WebApplication 的代码放到 BackgroundService 的ExecuteAsync方法中即可。 其中…

redis夯实之路-集群详解

Redis有单机模式和集群模式。 集群是 Redis 提供的分布式数据库方案&#xff0c;集群通过分片( sharding )来实现数据共享&#xff0c;并提供复制和故障转移。集群模式可以有多个 master 。使用集群模式可以进一步提升 Redis 性能&#xff0c;分布式部署实现高可用性&#xff…

快速了解——逻辑回归及模型评估方法

一、逻辑回归 应用场景&#xff1a;解决二分类问题 1、sigmoid函数 1. 公式&#xff1a; 2. 作用&#xff1a;把 (-∞&#xff0c;∞) 映射到 (0&#xff0c; 1) 3. 数学性质&#xff1a;单调递增函数&#xff0c;拐点在x0&#xff0c;y0.5的位置 4. 导函数公式&#xff1a;f…

MySQL 和 Redis 如何保证数据一致性,通过MySQL的binlog实现

1、简介 MySQL 和 Redis 如何保证数据一致性&#xff0c;目前大多讨论的是先更新Redis后更新MySQL&#xff0c;还是先更新MySQL 后更新Redis&#xff0c;这两种方式在实际的应用场景中都不能确保数据的完全一致性&#xff0c;在某些情况下会出现问题&#xff0c;本文介绍使用 C…