Skip to content

Commit 3c7174b

Browse files
committed
add tf.math.sigmoid
1 parent 87eac0c commit 3c7174b

4 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎src/TensorFlowNET.Core/APIs/tf.math.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ public static Tensor reduce_sum(Tensor input, int axis, int? reduction_indices =
281281
return math_ops.reduce_sum(input, axis);
282282
}
283283

284+
public static Tensor sigmoid<T>(T x, string name = null)
285+
=> math_ops.sigmoid(x, name: name);
286+
284287
public static Tensor sum(Tensor input, int axis, bool keep_dims = false, string name = null)
285288
=> gen_math_ops._sum(input, axis, keep_dims: keep_dims, name: name);
286289

‎src/TensorFlowNET.Core/Operations/gen_math_ops.cs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,26 @@ public static Tensor sin(Tensor x, string name = null)
108108
return _op.outputs[0];
109109
}
110110

111+
/// <summary>
112+
/// Computes sigmoid of <c>x</c> element-wise.
113+
/// </summary>
114+
/// <param name="x">
115+
/// </param>
116+
/// <param name="name">
117+
/// If specified, the created operation in the graph will be this one, otherwise it will be named 'Sigmoid'.
118+
/// </param>
119+
/// <returns>
120+
/// The Operation can be fetched from the resulting Tensor, by fetching the Operation property from the result.
121+
/// </returns>
122+
/// <remarks>
123+
/// Specifically, <c>y = 1 / (1 + exp(-x))</c>.
124+
/// </remarks>
125+
public static Tensor sigmoid(Tensor x, string name = "Sigmoid")
126+
{
127+
var op = _op_def_lib._apply_op_helper("Sigmoid", name: name, new { x });
128+
129+
return op.output;
130+
}
111131
public static Tensor sinh(Tensor x, string name = null)
112132
{
113133
var _op = _op_def_lib._apply_op_helper("Sinh", name, args: new { x });

‎src/TensorFlowNET.Core/Operations/math_ops.cs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,13 @@ public static Tensor reduce_prod(Tensor input_tensor, int[] axis = null, bool ke
119119
return _may_reduce_to_scalar(keepdims, axis, m);
120120
}
121121
}
122-
122+
123+
public static Tensor sigmoid<T>(T x, string name = null)
124+
{
125+
var x_tensor = ops.convert_to_tensor(x, name: "x");
126+
return gen_math_ops.sigmoid(x_tensor, name: name);
127+
}
128+
123129
/// <summary>
124130
/// Returns (x - y)(x - y) element-wise.
125131
/// </summary>

‎test/TensorFlowNET.UnitTest/PythonTest.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public T evaluate<T>(Tensor tensor)
143143
// return self._eval_helper(tensors)
144144
// else:
145145
{
146-
with(ops.get_default_session(), s =>
146+
with(tf.Session(), s =>
147147
{
148148
var ndarray=tensor.eval();
149149
if (typeof(T) == typeof(double))

0 commit comments

Comments
 (0)