lisp - LISP 使用负数作为指数
问题描述
我一直在尝试解决以下 Common Lisp 问题:
到目前为止,我有这个:
(defun activation (type sum)
"(type sum)
Returns the activation value of a connectionist unit
given a sum of products of input activations x
corresponding connection weights."
(cond ((equal type 'sigmoid) (- (/ 1 (+ 1 (exp (- 0 sum)))) 0.5))
((equal type 'asigmoid) ((/ 1 (+ 1 (exp (- 0 sum))))))
(t 'unknown-type)))
但是我在 exp 函数附近不断收到错误“类型错误”......有人可以帮我找出问题所在吗?
解决方案
您的代码中存在语法错误:
((/ 1 (+ 1 (exp (- 0 sum)))))
是一个无效的表达式(它有两个括号)。改变它
(/ 1 (+ 1 (exp (- 0 sum))))
在 Lisp 语言中,每个单独的括号都是一个重要的语法标记,而不是在其他语言中,其中(a + b)
和((a + b))
表示相同的表达式。
推荐阅读
- angular - 监听网络变化 - Ionic 2
- angular - PrimeNg 表,问题编辑复选框
- javascript - 如何从另一个组件定位组件内的引用?
- javascript - Bootstrap 4 ajax 加载模式
- angular - 在 IE 的小键盘上按下 ag-grid 中的带句点符号
- c# - ComboBox 的 SelectedItem 的变化改变了 ItemsSource
- kotlin - 为泛型类型添加静态扩展
- logging - 检测到 Logback 配置错误
- nginx - 无法选择合适的插件:nginx 插件不起作用;
- time-complexity - 检查二叉树是否为 avl 树的最佳时间复杂度(高度平衡)