|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2025 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# logitf |
| 22 | + |
| 23 | +> Compute the [logit][logit] function for a single-precision floating-point number. |
| 24 | +
|
| 25 | +<section class="intro"> |
| 26 | + |
| 27 | +The [logit][logit] function is defined as the logarithm of the odds `p / (1-p)`; i.e., |
| 28 | + |
| 29 | +<!-- <equation class="equation" label="eq:logitf_function" align="center" raw="\operatorname{logitf}(p)=\log \left({\frac {p}{1-p}}\right)" alt="Logitf function."> --> |
| 30 | + |
| 31 | +```math |
| 32 | +\mathop{\mathrm{logitf}}(p)=\log \left({\frac {p}{1-p}}\right) |
| 33 | +``` |
| 34 | + |
| 35 | +<!-- </equation> --> |
| 36 | + |
| 37 | +The [logit][logit] function is the inverse of the [standard logistic][standard-logistic] function, sometimes also called the sigmoid function. |
| 38 | + |
| 39 | +</section> |
| 40 | + |
| 41 | +<!-- /.intro --> |
| 42 | + |
| 43 | +<section class="usage"> |
| 44 | + |
| 45 | +## Usage |
| 46 | + |
| 47 | +```javascript |
| 48 | +var logitf = require( '@stdlib/math/base/special/logitf' ); |
| 49 | +``` |
| 50 | + |
| 51 | +#### logitf( p ) |
| 52 | + |
| 53 | +Computes the [logit][logit] function for a single-precision floating-point number. |
| 54 | + |
| 55 | +```javascript |
| 56 | +var v = logitf( 0.2 ); |
| 57 | +// returns ~-1.386 |
| 58 | + |
| 59 | +v = logitf( 0.9 ); |
| 60 | +// returns ~2.197 |
| 61 | +``` |
| 62 | + |
| 63 | +If `p < 0` or `p > 1`, the function returns `NaN`. |
| 64 | + |
| 65 | +```javascript |
| 66 | +var v = logitf( 1.3 ); |
| 67 | +// returns NaN |
| 68 | + |
| 69 | +v = logitf( -0.2 ); |
| 70 | +// returns NaN |
| 71 | +``` |
| 72 | + |
| 73 | +</section> |
| 74 | + |
| 75 | +<!-- /.usage --> |
| 76 | + |
| 77 | +<section class="examples"> |
| 78 | + |
| 79 | +## Examples |
| 80 | + |
| 81 | +<!-- eslint no-undef: "error" --> |
| 82 | + |
| 83 | +```javascript |
| 84 | +var uniform = require( '@stdlib/random/array/uniform' ); |
| 85 | +var logEachMap = require( '@stdlib/console/log-each-map' ); |
| 86 | +var logitf = require( '@stdlib/math/base/special/logitf' ); |
| 87 | + |
| 88 | +var opts = { |
| 89 | + 'dtype': 'float32' |
| 90 | +}; |
| 91 | +var p = uniform( 100, 0.0, 1.0, opts ); |
| 92 | + |
| 93 | +logEachMap( 'logitf(%0.4f) = %0.4f', p, logitf ); |
| 94 | +``` |
| 95 | + |
| 96 | +</section> |
| 97 | + |
| 98 | +<!-- /.examples --> |
| 99 | + |
| 100 | +<!-- C interface documentation. --> |
| 101 | + |
| 102 | +* * * |
| 103 | + |
| 104 | +<section class="c"> |
| 105 | + |
| 106 | +## C APIs |
| 107 | + |
| 108 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 109 | + |
| 110 | +<section class="intro"> |
| 111 | + |
| 112 | +</section> |
| 113 | + |
| 114 | +<!-- /.intro --> |
| 115 | + |
| 116 | +<!-- C usage documentation. --> |
| 117 | + |
| 118 | +<section class="usage"> |
| 119 | + |
| 120 | +### Usage |
| 121 | + |
| 122 | +```c |
| 123 | +#include "stdlib/math/base/special/logitf.h" |
| 124 | +``` |
| 125 | + |
| 126 | +#### stdlib_base_logitf( p ) |
| 127 | + |
| 128 | +Computes the [logit][logit] function for a single-precision floating-point number. |
| 129 | + |
| 130 | +```c |
| 131 | +float out = stdlib_base_logitf( 0.2f ); |
| 132 | +// returns ~-1.386f |
| 133 | + |
| 134 | +out = stdlib_base_logitf( 0.9f ); |
| 135 | +// returns ~2.197f |
| 136 | +``` |
| 137 | + |
| 138 | +The function accepts the following arguments: |
| 139 | + |
| 140 | +- **p**: `[in] float` input value. |
| 141 | + |
| 142 | +```c |
| 143 | +float stdlib_base_logitf( const float p ); |
| 144 | +``` |
| 145 | +
|
| 146 | +</section> |
| 147 | +
|
| 148 | +<!-- /.usage --> |
| 149 | +
|
| 150 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 151 | +
|
| 152 | +<section class="notes"> |
| 153 | +
|
| 154 | +</section> |
| 155 | +
|
| 156 | +<!-- /.notes --> |
| 157 | +
|
| 158 | +<!-- C API usage examples. --> |
| 159 | +
|
| 160 | +<section class="examples"> |
| 161 | +
|
| 162 | +### Examples |
| 163 | +
|
| 164 | +```c |
| 165 | +#include "stdlib/math/base/special/logitf.h" |
| 166 | +#include <stdlib.h> |
| 167 | +#include <stdio.h> |
| 168 | +
|
| 169 | +int main( void ) { |
| 170 | + float x; |
| 171 | + float v; |
| 172 | + int i; |
| 173 | +
|
| 174 | + for ( i = 0; i < 100; i++ ) { |
| 175 | + x = (float)rand() / (float)RAND_MAX; |
| 176 | + v = stdlib_base_logitf( x ); |
| 177 | + printf( "logitf(%f) = %f\n", x, v ); |
| 178 | + } |
| 179 | +} |
| 180 | +``` |
| 181 | + |
| 182 | +</section> |
| 183 | + |
| 184 | +<!-- /.examples --> |
| 185 | + |
| 186 | +</section> |
| 187 | + |
| 188 | +<!-- /.c --> |
| 189 | + |
| 190 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 191 | + |
| 192 | +<section class="related"> |
| 193 | + |
| 194 | +</section> |
| 195 | + |
| 196 | +<!-- /.related --> |
| 197 | + |
| 198 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 199 | + |
| 200 | +<section class="links"> |
| 201 | + |
| 202 | +[logit]: https://en.wikipedia.org/wiki/Logit |
| 203 | + |
| 204 | +[standard-logistic]: https://en.wikipedia.org/wiki/Logistic_function |
| 205 | + |
| 206 | +<!-- <related-links> --> |
| 207 | + |
| 208 | +<!-- </related-links> --> |
| 209 | + |
| 210 | +</section> |
| 211 | + |
| 212 | +<!-- /.links --> |
0 commit comments