H5白鹭中实现人工神经网络【语言:Typescripts】

/**
 * 神经网络
 */
class NeuralNetwork {
	public layerinfo:number[];//神经层结构
	public neuralLayerList: List;
	public gene: number[];//偏执
	public get Gene(): number[] {
		return this.gene;
	}
	// public set Gene(any: number[]) {
	// 	//this.gene = any;
	// 	this.LoadGene(any);
	// }
	public constructor(layerinfo: number[]) {
		this.layerinfo=layerinfo;
		this.neuralLayerList = new List();
		for (let i = 0; i < layerinfo.length; i++) {
			this.neuralLayerList.AddValue(new NeuralLayer(i, layerinfo));//初始化所有层神经元
		}
		//输入层无偏执和权重
		for (let i = 1; i < this.neuralLayerList.Count; i++) {
			for (var j in this.neuralLayerList[i].neurals) {
				this.gene.push[this.neuralLayerList[i].neurals[j].stubborn];//加偏执
				for (var k in this.neuralLayerList[i].neurals[j].weights) {
					this.gene.push[this.neuralLayerList[i].neurals[j].weights[k]];//加权重
				}
			}
		}

	}
	//是否load保存好的权重
	public LoadGene(gene: number[]) {
		var index = 0;
		for (let i = 1; i < this.neuralLayerList.Count; i++) {
			for (var j in this.neuralLayerList[i].neurals) {
				this.neuralLayerList[i].neurals[j].stubborn = gene[index];//偏执
				this.gene[index]=gene[index];
				index++;
				for (var k in this.neuralLayerList[i].neurals[j].weights) {
					this.neuralLayerList[i].neurals[j].weights[k] = gene[index];//权重
					this.gene[index]=gene[index];
					index++;
				}
			}
		}
	}
	//输入-->输出
	public Pushout(inputs: number[]): number[] {
		return this.Compute(inputs);
	}
	private Compute(inputs: number[]): number[] {
		//输入层
		var inputneurals: NeuralLayer = this.neuralLayerList[0].neurals;
		for (var i in inputneurals) {
			inputneurals[i].value = inputs[i];
		}
		//隐藏层
		for (let i = 1; i < this.neuralLayerList.Count; i++) {
			var upperneurals: List = this.neuralLayerList[i - 1].neurals;
			var curneurals: List = this.neuralLayerList[i].neurals;
			for (var j in curneurals) {
				curneurals[j].value = 0;
				for (var k in upperneurals) {
					curneurals[j].value += MathTool.ActivationFunction(curneurals[j].weights[k] * upperneurals[k].value + curneurals[j].stubborn);
				}
			}
		}
		//输出层
		var outputneurals: List = this.neuralLayerList[this.neuralLayerList.Count - 1].neurals;
		var outputs: number[];
		for (var i in outputneurals) {
			outputs.push(outputneurals[i]);
		}
		return outputs;
	}
}
/**
 * 神经层
 */
class NeuralLayer {
	public neurals: List;
	public constructor(index: number, layerinfo: number[]) {
		this.neurals = new List();
		var weightcount = 0;
		if (index == 0)
			weightcount = 0;
		else
			weightcount = layerinfo[index - 1];
		for (let i = 0; i < layerinfo[index]; i++) {
			this.neurals.AddValue(new Neural(weightcount));
		}
	}
}
/**
 * 神经元
 */
class Neural {
	public stubborn: number;//偏执
	public weights: number[];//权重
	public value: number;//计算后的值
	public constructor(weightcount: number) {
		for (let i = 0; i < weightcount; i++) {
			this.weights.push(MathTool.Random());
		}
	}

}

 

要成功匹配表格某一列在字典中的数据,你可以按照以下步骤进行操作: 1. 确保你已经安装了 EleAdminPro 前端框架,并且已经集成了 Vue3、Ant Desgin Vue、Vite、TypeScripts。 2. 创建一个字典,将需要匹配的数据存储在字典中。字典的结构可以根据你的需求进行定义,可以是一个数组、对象或者Map。 3. 在表格的列配置中,找到需要匹配的列,给该列添加一个自定义的渲染函数。 4. 在自定义的渲染函数中,通过传入的参数获取当前行的数据,并从字典中查找对应的值。 5. 根据查找到的值进行渲染,可以使用 Ant Design Vue 提供的组件或者自定义展示方式。 以下是一个简单的示例代码: ```vue <template> <a-table :columns="columns" :data-source="dataSource"></a-table> </template> <script> export default { data() { return { dataSource: [ { id: 1, name: 'John', gender: 'M' }, { id: 2, name: 'Jane', gender: 'F' }, ], genderDict: { M: 'Male', F: 'Female', }, columns: [ { title: 'ID', dataIndex: 'id', key: 'id' }, { title: 'Name', dataIndex: 'name', key: 'name' }, { title: 'Gender', dataIndex: 'gender', key: 'gender', customRender: (text, record, index) => { return this.genderDict[text]; }, }, ], }; }, }; </script> ``` 在上述示例中,我们创建了一个名为 `genderDict` 的字典,用于将性别的缩写转换为全称。然后在列配置中,对 `Gender` 列使用了自定义的渲染函数,在渲染函数中根据当前行的 `gender` 值从字典中获取对应的全称进行展示。 你可以根据自己的实际需求进行修改和扩展,希望对你有所帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值