随笔分类 - 代码
摘要:* ortools 中提供了一个文档介绍快速具体算法 https://developers.google.cn/optimization/lp/lp_advanced?hl=en 其中实现了一个迭代法 PDLP, 对于低精度,以及给定初值的情况应该比较有利。 文档没有提供例子, 但代码路中有例子:
阅读全文
摘要:```python import time import tensorflow as tf tf.compat.v1.disable_eager_execution() #%% 平均2.7秒。 发现conda 创建tf1.15 速度非常慢,应该环境配置有问题 A = tf.linalg.svd(tf
阅读全文
摘要:```python # %% import jax import jax.numpy as jnp import numpy as np def loss(params, r): lambda_a, lambda_s = params return jnp.maximum(r - lambda_a
阅读全文
摘要:好几年前写的代码, 其中javascript代码找专业人员写的。 ```python #######页面 _HTML = ''' 效果分析%(bizdate)s 算法效果报告 bizdate=%(bizdate)s %(tabs)s %(contents)s 注意数据安全, 请勿转发!! 有问题联系
阅读全文
摘要:0. 官方教材 https://pytorch.org/tutorials/beginner/basics/tensorqs_tutorial.html 1. https://huhuhang.com/post/machine-learning/pytorch-basic-tutorials 2.
阅读全文
摘要:* 用md5 ```python import hashlib _a = hashlib.md5(_model_file.encode('utf-8')).hexdigest() resource_name = f'tfmodel_{_a}.tar.gz' ``` * 不能缩短 ```python
阅读全文
摘要:之前的一段java代码, 发现耗时有点高, java 同事做了优化。方法如下: 1. 写一个测试类, profileTest分析代码中各部分的耗时。 2. 把java的split 的代码用for循环 去处理。 最终耗时从16ms下降到9ms。 想了下 java split 慢, 可能是正则表达式原因
阅读全文
摘要:* https://www.tutorialspoint.com/rust/rust_tutorial.pdf 150页 * https://lise-henry.github.io/books/trpl2.pdf 600页 * https://edu.anarcho-copy.org/Progra
阅读全文
摘要:* tf.switch_case, 1.15 以后版本生效 * fast_net 中不能用 lambda 函数, 否则结果不一致。 ```python def fast_net(branch_index, branch_names=branch_names): import functools br
阅读全文
摘要:参考 tf.metrics.mean, 编写一个广告中常用的pcoc 度量,在tf.esitmator 模型中使用 ```python class Kmetrics(object): @staticmethod def pcoc(labels, predictions, weights=None,
阅读全文
摘要:稀疏的string tensor 转dense, 每行一个值 ```python tf.sparse.to_dense(sp_x) ``` 或者 ```python def to_dense_mx1(sp): sp_x = tf.SparseTensor(indices=tf.concat((sp.
阅读全文
摘要:```python import json import base64 # 输入 x = dict(a=1, b='555', name='中文') # 编码 y = json.dumps(x, indent=2).encode('utf-8') with open('b64.txt', 'wb')
阅读全文
摘要:* 必须捕获与非必须捕获异常。 用RuntimeException 抛出提示 ```java try { // todo } catch (Exception e) { String message = String.format("record=%s,keys=%s",checkPoints, a
阅读全文
摘要:2023更新 这本不错 https://course.rs/about-book.html 加了代理 cat $HOME/.cargo/config.toml [source.crates-io] replace-with = 'rsproxy' [source.rsproxy] registry
阅读全文
摘要:* keys_len 如果是None的时候, 注释代码失败。 ```python # keys_len = keys.get_shape()[1] # queries = K.repeat_elements(query, keys_len, 1) keys_len = tf.shape(keys)[
阅读全文
摘要:```python tf.app.flags.DEFINE_integer('num_blocks', 1, 'Number of blocks in each attention') tf.app.flags.DEFINE_integer('num_heads', 8, 'Number of he
阅读全文
摘要:```python # 计算正则项 # t_l2_reg = tf.nn.l2_loss(emb, name=reg_name) * l2_reg t_l2_reg = tf.reduce_mean(tf.reduce_sum(emb**2, axis=-1), name=reg_name) * l
阅读全文
摘要:* 分桶 获取ID ``` In [27]: sess= tf.InteractiveSession() In [31]: from tensorflow.contrib.layers.python.ops import bucketization_op In [32]: a= bucketizat
阅读全文
摘要:```python def kv2sparse(lines, num_cols, sep=',', kv_sep=':', hash_key=False): """ 解析kv格式的数据. Parameters lines : string or string tensor the input dat
阅读全文
摘要:```python import threading def _task(func, args, n_thread=8): # 多线程并发执行所有任务 threads = map(lambda : threading.Thread(target=func, args=args), range(len
阅读全文