I have prepared some functions to generate tables in SPSS but at this moment I have to convert all these tables to Custom Tables. I found out that I can use SPSS Syntax Converter script instead of writting a new code from the beginning, which will change code related to tables and provide appropiate custom table counterpart. On IBM website I found informations about limitations of this method, I tried to change variable names in my code and delete, but every time i get only an error. What should I change in my table syntax to have functional Syntax Converter? What shape should it have? Below is my example.
DEFINE !TABLE (!pos = !tokens(1) /!pos = !tokens(1) /!pos= !tokens(1)/!pos = !tokens(1) /!pos = !tokens(1) /!pos = !tokens(1) /!pos= !tokens(1)/!pos = !tokens(1) /!pos = !tokens(1) /!pos= !tokens(1)/!pos = !tokens(1) /!pos = !tokens(1) /!pos= !tokens(1)/!pos = !tokens(1) /!pos = !tokens(1) /!pos = !tokens(1) /!pos= !tokens(1)/!pos = !tokens(1) /!pos = !tokens(1) /!pos= !tokens(1)).
TEMPORARY.
VARIABLE LABELS !1 ''.
TABLES /Format BLANK MISSING('.')
/GBASE=CASES
/PTOTAL= $t000002 '$/Total' $t000001 '$/Total'
/TABLE=$t000002 + !1 BY $t000001+ !2+ !3+ !4+ !5+ !6+ !7+ !8+ !9+ !10
/STATISTIC count( !1( F5.0 )'$$Count') cpct( !1( F5.2 ) '$$Column-%': !2 !3 !4 !5 !6 !7 !8 !9 !10) cpct( !1( F5.2 ) '$$Row-%':!1)
/TITLE = !11 !ENDDEFINE.
Related
I use the following code to winsorize variables in my dataset using SPSS. In the line where it says COMPUTE !var = MAX(MIN(!var, maxval), minval)., I want it to create a new variable with _w as the suffix. Of course, COMPUTE !var_w = MAX(MIN(!var, maxval), minval). will not work. Any solutions, preferably without using Python? Also, is there a way to loop this so that I can include more than one variable when I execute it? For example, !winsor vars = roa, leverage, roe lowpc = 1 hipc = 1..
DEFINE !winsor (var = !TOKENS(1) / lowpc = !TOKENS(1) / hipc = !TOKENS(1))
COMPUTE nobreak=1.
RANK VARIABLES = !var (A) BY nobreak /PERCENT INTO pc_ /PRINT = YES /TIES = MEAN.
XSAVE OUTFILE = 'data.sav'.
SORT CASES BY pc_ (D).
SELECT IF pc_ <= !lowpc.
N OF CASES 1.
RENAME VARIABLE (!var = minval).
SAVE OUTFILE = 'minval.sav' /KEEP = nobreak minval.
GET FILE='data.sav'.
SELECT IF pc_ >= (!hipc).
SORT CASES BY pc_ (A).
N OF CASES 1.
RENAME VARIABLE (!var = maxval).
SAVE OUTFILE = 'maxval.sav' /KEEP = nobreak maxval.
MATCH FILES FILE = 'data.sav'
/TABLE = 'minval.sav'
/TABLE = 'maxval.sav'
/BY = nobreak
/DROP = nobreak.
COMPUTE !var_w = MAX(MIN(!var, maxval), minval).
EXECUTE.
DELETE VARIABLES pc_ minval maxval.
DATASET CLOSE DataSet1.
EXECUTE.
!ENDDEFINE.
!winsor var = roa lowpc = 1 hipc = 1.
In order to add a suffix to your new variable name you need to use the spss macro command !concat like this:
COMPUTE !concat(!var,"_w") = MAX(MIN(!var, maxval), minval).
In order to do this for a list of variables you can use a macro loop:
define macrowithloop(vrs=!cmdend)
!do !vr !in(!vrs)
* do stuff.
COMPUTE !concat(!vr,"_w") = MAX(MIN(!vr, maxval), minval).
* other stuff.
!doend
!enddefine.
macrowithloop vars=roa leverage roe lowpc .
I'm trying to create a Gaussian HMM model in pyro to infer the parameters of a very simple Markov sequence. However, my model fails to infer the parameters and something wired happened during the training process. Using the same sequence, hmmlearn has successfully infer the true parameters.
Full code can be accessed in here:
https://colab.research.google.com/drive/1u_4J-dg9Y1CDLwByJ6FL4oMWMFUVnVNd#scrollTo=ZJ4PzdTUBgJi
My model is modified from the example in here:
https://github.com/pyro-ppl/pyro/blob/dev/examples/hmm.py
I manually created a first order Markov sequence where there are 3 states, the true means are [-10, 0, 10], sigmas are [1,2,1].
Here is my model
def model(observations, num_state):
assert not torch._C._get_tracing_state()
with poutine.mask(mask = True):
p_transition = pyro.sample("p_transition",
dist.Dirichlet((1 / num_state) * torch.ones(num_state, num_state)).to_event(1))
p_init = pyro.sample("p_init",
dist.Dirichlet((1 / num_state) * torch.ones(num_state)))
p_mu = pyro.param(name = "p_mu",
init_tensor = torch.randn(num_state),
constraint = constraints.real)
p_tau = pyro.param(name = "p_tau",
init_tensor = torch.ones(num_state),
constraint = constraints.positive)
current_state = pyro.sample("x_0",
dist.Categorical(p_init),
infer = {"enumerate" : "parallel"})
for t in pyro.markov(range(1, len(observations))):
current_state = pyro.sample("x_{}".format(t),
dist.Categorical(Vindex(p_transition)[current_state, :]),
infer = {"enumerate" : "parallel"})
pyro.sample("y_{}".format(t),
dist.Normal(Vindex(p_mu)[current_state], Vindex(p_tau)[current_state]),
obs = observations[t])
My model is compiled as
device = torch.device("cuda:0")
obs = torch.tensor(obs)
obs = obs.to(device)
torch.set_default_tensor_type("torch.cuda.FloatTensor")
guide = AutoDelta(poutine.block(model, expose_fn = lambda msg : msg["name"].startswith("p_")))
Elbo = Trace_ELBO
elbo = Elbo(max_plate_nesting = 1)
optim = Adam({"lr": 0.001})
svi = SVI(model, guide, optim, elbo)
As the training goes, the ELBO has decreased steadily as shown. However, the three means of the states converges.
I have tried to put the for loop of my model into a pyro.plate and switch pyro.param to pyro.sample and vice versa, but nothing worked for my model.
I have not tried this model, but I think it should be possible to solve the problem by modifying the model in the following way:
def model(observations, num_state):
assert not torch._C._get_tracing_state()
with poutine.mask(mask = True):
p_transition = pyro.sample("p_transition",
dist.Dirichlet((1 / num_state) * torch.ones(num_state, num_state)).to_event(1))
p_init = pyro.sample("p_init",
dist.Dirichlet((1 / num_state) * torch.ones(num_state)))
p_mu = pyro.sample("p_mu",
dist.Normal(torch.zeros(num_state), torch.ones(num_state)).to_event(1))
p_tau = pyro.sample("p_tau",
dist.HalfCauchy(torch.zeros(num_state)).to_event(1))
current_state = pyro.sample("x_0",
dist.Categorical(p_init),
infer = {"enumerate" : "parallel"})
for t in pyro.markov(range(1, len(observations))):
current_state = pyro.sample("x_{}".format(t),
dist.Categorical(Vindex(p_transition)[current_state, :]),
infer = {"enumerate" : "parallel"})
pyro.sample("y_{}".format(t),
dist.Normal(Vindex(p_mu)[current_state], Vindex(p_tau)[current_state]),
obs = observations[t])
The model would then be trained using MCMC:
# MCMC
hmc_kernel = NUTS(model, target_accept_prob = 0.9, max_tree_depth = 7)
mcmc = MCMC(hmc_kernel, num_samples = 1000, warmup_steps = 100, num_chains = 1)
mcmc.run(obs)
The results could then be analysed using:
mcmc.get_samples()
Log4j2 provides various kind of filters [1] and these can be configured at four levels:
Context-wide
Logger
Appender
Appender Reference
In my use-case, I would like to setup a CompositeFilter at a specified Logger (level 2 from above) using the property file syntax.
For the sake of the example let's assume that we want to setup a composite filter composed from two RegexFilter matching .*SQL.* and .*JPQL.* respectively. Assuming that we have the following events:
logger.info("Messase with no keyword");
logger.info("Messase with SQL keyword");
logger.info("Messase with JPQL keyword");
logger.info("Messase with both SQL and JPQL keywords");
Only the last event should pass from the composite filter.
I made several attempts [2] (also outlined below) to get the desired output but I wasn't able to figure out how to properly setup a CompositeFilter using the property syntax so any help would be greatly appreciated.
Attempt 0
logger.t1.filter.f1.type = RegexFilter
logger.t1.filter.f1.regex = .*SQL.*
logger.t1.filter.f1.onMatch = NEUTRAL
logger.t1.filter.f1.onMismatch = DENY
logger.t1.filter.f2.type = RegexFilter
logger.t1.filter.f2.regex = .*JPQL.*
logger.t1.filter.f2.onMatch = ACCEPT
logger.t1.filter.f2.onMismatch = DENY
logger.t1.appenderRefs = a
logger.t1.appenderRef.a.ref = L0
Attempt 1
logger.t1.filters = f1, f2
logger.t1.filter.f1.type = RegexFilter
logger.t1.filter.f1.regex = .*SQL.*
logger.t1.filter.f1.onMatch = NEUTRAL
logger.t1.filter.f1.onMismatch = DENY
logger.t1.filter.f2.type = RegexFilter
logger.t1.filter.f2.regex = .*JPQL.*
logger.t1.filter.f2.onMatch = ACCEPT
logger.t1.filter.f2.onMismatch = DENY
Attempt 2
logger.t1.filters.f1.type = RegexFilter
logger.t1.filters.f1.regex = .*SQL.*
logger.t1.filters.f1.onMatch = NEUTRAL
logger.t1.filters.f1.onMismatch = DENY
logger.t1.filters.f2.type = RegexFilter
logger.t1.filters.f2.regex = .*JPQL.*
logger.t1.filters.f2.onMatch = ACCEPT
logger.t1.filters.f2.onMismatch = DENY
logger.t1.appenderRefs = a
logger.t1.appenderRef.a.ref = L0
Attempt 3
logger.t1.filter.M.type = Filters
logger.t1.filter.M.f1.type = RegexFilter
logger.t1.filter.M.f1.regex = .*SQL.*
logger.t1.filter.M.f1.onMatch = NEUTRAL
logger.t1.filter.M.f1.onMismatch = DENY
logger.t1.filter.M.f2.type = RegexFilter
logger.t1.filter.M.f2.regex = .*JPQL.*
logger.t1.filter.M.f2.onMatch = ACCEPT
logger.t1.filter.M.f2.onMismatch = DENY
logger.t1.appenderRefs = a
logger.t1.appenderRef.a.ref = L0
Some further clarifications:
I am strictly interested for setting up a CompositeFilter, not
write a custom filter, not use a single combined RegexFilter etc.
I am interested to see how it is done using the property syntax, not
XML, JSON, or other.
[1] https://logging.apache.org/log4j/2.x/manual/filters.html
[2] https://github.com/zabetak/logging-log4j2/commit/a9944885100db42f7e3ba1b3ff81d59b743d0ab7
There are two problems with your configuration:
A LoggerConfig accepts only a single filter. If you want to use multiple filters, configure a CompositeFilter explicitly (which has a plugin name "Filters),
The order of filters in a properties configuration file is basically random, since Properties is a Hashtable and does not have a predefined order.
Considering the two facts above a variation of your attempt 3 should work:
logger.t1.filter.M.type = Filters
logger.t1.filter.M.f1.type = RegexFilter
logger.t1.filter.M.f1.regex = .*SQL.*
logger.t1.filter.M.f1.onMatch = NEUTRAL
logger.t1.filter.M.f1.onMismatch = DENY
logger.t1.filter.M.f2.type = RegexFilter
logger.t1.filter.M.f2.regex = .*JPQL.*
logger.t1.filter.M.f2.onMatch = NEUTRAL
logger.t1.filter.M.f2.onMismatch = DENY
Both filters return NEUTRAL, when the pattern matches, which guarantees that an inversion of the order of filters does not break the logic.
I have a problem, so I have a huge table where some fields contain only numbers from 1-20 and I want to move the values of the fields to a new table where there are 3 fields with a name and the number (zjdc01 or zadc01).
Now I want to check the field value from the huge table and append the values to the new fields.
For Example :
CASE LS_ATLAS_DC-ZJDC01.
WHEN 1.
LS_ATLAS-ZJDC01 = LS_ATLAS_DC-ZJDC01.
LS_ATLAS-ZADC01 = LS_ATLAS_DC-ZADC01.
LS_ATLAS-ZBDC01 = LS_ATLAS_DC-ZBDC01.
WHEN 2.
LS_ATLAS-ZJDC02 = LS_ATLAS_DC-ZJDC01.
LS_ATLAS-ZADC02 = LS_ATLAS_DC-ZADC01.
LS_ATLAS-ZBDC02 = LS_ATLAS_DC-ZBDC01.
WHEN 3.
LS_ATLAS-ZJDC03 = LS_ATLAS_DC-ZJDC01.
LS_ATLAS-ZADC03 = LS_ATLAS_DC-ZADC01.
LS_ATLAS-ZBDC03 = LS_ATLAS_DC-ZBDC01.
WHEN 4.
LS_ATLAS-ZJDC04 = LS_ATLAS_DC-ZJDC01.
LS_ATLAS-ZADC04 = LS_ATLAS_DC-ZADC01.
LS_ATLAS-ZBDC04 = LS_ATLAS_DC-ZBDC01.
But this is very exhausting and I think there is another Solution but I dont know if ABAP have something for this.
Maybe some of you have a Solution or have a similiar problem which he solved.
Use ASSIGN COMPONENT name OF STRUCTURE structure TO <field_symbol>.
DATA name TYPE string. " component name
FIELD-SYMBOLS: <zjdc_xx> TYPE any,
<zadc_xx> TYPE any,
<zbdc_xx> TYPE any.
IF number BETWEEN 1 and 4.
name = |ZJDC{ number WIDTH = 2 ALIGN = RIGHT PAD = '0' }|. "<== ZJDC01 to ZJDC04
ASSIGN COMPONENT name OF STRUCTURE ls_atlas TO <zjdc_xx>.
name = |ZADC{ number WIDTH = 2 ALIGN = RIGHT PAD = '0' }|. "<== ZADC01 to ZADC04
ASSIGN COMPONENT name OF STRUCTURE ls_atlas TO <zadc_xx>.
name = |ZBDC{ number WIDTH = 2 ALIGN = RIGHT PAD = '0' }|. "<== ZBDC01 to ZBDC04
ASSIGN COMPONENT name OF STRUCTURE ls_atlas TO <zbdc_xx>.
<zjdc_xx> = LS_ATLAS_DC-ZJDC01.
<zadc_xx> = LS_ATLAS_DC-ZADC01.
<zbdc_xx> = LS_ATLAS_DC-ZBDC01.
ENDIF.
I must replace all of these characters, "①②③④⑤⑥⑦⑧⑨⑩", with "\item".
I have used this code:
stra = string.gsub(text, "①", "\\item")
strb = string.gsub(stra, "②", "\\item")
strc = string.gsub(strb, "③", "\\item")
strd = string.gsub(strc, "④", "\\item")
stre = string.gsub(strd, "⑤", "\\item")
However, this is very verbose. Is there a simpler way to replace all of those items?
local symbols_trans = {
["\226\145\160"]--[[①]] = "\\item1",
["\226\145\161"]--[[②]] = "\\bananas",
["\226\145\162"]--[[③]] = "\\cactus",
["\226\145\163"]--[[④]] = "\\etc",
["\226\145\164"]--[[⑤]] = "\\item5",
["\226\145\165"]--[[⑥]] = "\\item6",
["\226\145\166"]--[[⑦]] = "\\item7",
["\226\145\167"]--[[⑧]] = "\\item8",
["\226\145\168"]--[[⑨]] = "\\item9",
["\226\145\169"]--[[⑩]] = "\\item10",
}
text = string.gsub(text, "(\266\145.)", symbol_trans)
Or if you want to replace them all with"\\item":
text = string.gsub(text,
"\266\145[\160-\169]",
"\\item"
)
[\160-\169] is equivalent to [\160\161\162\163\164\165\166\167\168\169].
See the Lua manual for information on ranges and, in general, Lua patterns.
You could also be fancy:
text = string.gsub(text,
"\266\145([\160-169])",
function(c)
return "\\item"..(string.byte(c)-160+1)
end
)
This will turn ① into \item1, ② into \item2, and so on.
Use a "set" as described in the tutorial: http://lua-users.org/wiki/PatternsTutorial
string.gsub(text, "[①②③④⑤⑥⑦⑧⑨⑩]", "\\item")
Is there a simpler way to replace all of those items?
Not without a Lua pattern matching library that knows what UTF-8 is. Lua is not Unicode aware; it has no idea how to search for Unicode symbols.
If you're using some non-multibyte encoding, then what John suggested might work. But not if it's UTF-8.
For your specific case, you could always do this:
local symbolsToChange { "①", "②", ...}
for i, sym in ipairs(symbolsToChange) do
string.gsub(text, sym, "\\item")
end